CI_Loader Class Reference

Inheritance diagram for CI_Loader:

List of all members.


Public Member Functions

 CI_Loader ()
 Constructor.
 library ($library= '', $params=NULL)
 Class Loader.
 model ($model, $name= '', $db_conn=FALSE)
 Model Loader.
 database ($params= '', $return=FALSE, $active_record=FALSE)
 Database Loader.
 dbutil ()
 Load the Utilities Class.
 dbforge ()
 Load the Database Forge Class.
 view ($view, $vars=array(), $return=FALSE)
 Load View.
 file ($path, $return=FALSE)
 Load File.
 vars ($vars=array())
 Set Variables.
 helper ($helpers=array())
 Load Helper.
 helpers ($helpers=array())
 Load Helpers.
 plugin ($plugins=array())
 Load Plugin.
 plugins ($plugins=array())
 Load Plugins.
 script ($scripts=array())
 Load Script.
 language ($file=array(), $lang= '')
 Loads a language file.
 scaffold_language ($file= '', $lang= '', $return=FALSE)
 Loads language files for scaffolding.
 config ($file= '', $use_sections=FALSE, $fail_gracefully=FALSE)
 Loads a config file.
 scaffolding ($table= '')
 Scaffolding Loader.
 _ci_load ($_ci_data)
 Loader.
 _ci_load_class ($class, $params=NULL)
 Load class.
 _ci_init_class ($class, $prefix= '', $config=FALSE)
 Instantiates a class.
 _ci_autoloader ()
 Autoloader.
 _ci_assign_to_models ()
 Assign to Models.
 _ci_object_to_array ($object)
 Object to Array.
 _ci_is_instance ()
 Determines whether we should use the CI instance or $this.

Public Attributes

 $_ci_ob_level
 $_ci_view_path = ''
 $_ci_is_php5 = FALSE
 $_ci_is_instance = FALSE
 $_ci_cached_vars = array()
 $_ci_classes = array()
 $_ci_models = array()
 $_ci_helpers = array()
 $_ci_plugins = array()
 $_ci_scripts = array()
 $_ci_varmap = array('unit_test' => 'unit', 'user_agent' => 'agent')

Detailed Description

Definition at line 29 of file Loader.php.


Member Function Documentation

CI_Loader::_ci_assign_to_models (  ) 

Assign to Models.

Makes sure that anything loaded by the loader class (libraries, plugins, etc.) will be available to models, if any exist.

private

Parameters:
object 
Returns:
array

Definition at line 970 of file Loader.php.

References $CI, _ci_is_instance(), and get_instance().

Referenced by database(), and library().

00971         {
00972                 if (count($this->_ci_models) == 0)
00973                 {
00974                         return;
00975                 }
00976         
00977                 if ($this->_ci_is_instance())
00978                 {
00979                         $CI =& get_instance();
00980                         foreach ($this->_ci_models as $model)
00981                         {                       
00982                                 $CI->$model->_assign_libraries();
00983                         }
00984                 }
00985                 else
00986                 {               
00987                         foreach ($this->_ci_models as $model)
00988                         {                       
00989                                 $this->$model->_assign_libraries();
00990                         }
00991                 }
00992         }       

Here is the call graph for this function:

Here is the caller graph for this function:

CI_Loader::_ci_autoloader (  ) 

Autoloader.

The config/autoload.php file contains an array that permits sub-systems, libraries, plugins, and helpers to be loaded automatically.

private

Parameters:
array 
Returns:
void

Definition at line 889 of file Loader.php.

References $autoload, $CI, database(), get_instance(), library(), model(), and scaffolding().

Referenced by Controller::_ci_initialize().

00890         {       
00891                 include_once(APPPATH.'config/autoload'.EXT);
00892                 
00893                 if ( ! isset($autoload))
00894                 {
00895                         return FALSE;
00896                 }
00897                 
00898                 // Load any custom config file
00899                 if (count($autoload['config']) > 0)
00900                 {                       
00901                         $CI =& get_instance();
00902                         foreach ($autoload['config'] as $key => $val)
00903                         {
00904                                 $CI->config->load($val);
00905                         }
00906                 }               
00907 
00908                 // Autoload plugins, helpers and languages
00909                 foreach (array('helper', 'plugin', 'language') as $type)
00910                 {                       
00911                         if (isset($autoload[$type]) AND count($autoload[$type]) > 0)
00912                         {
00913                                 $this->$type($autoload[$type]);
00914                         }               
00915                 }
00916 
00917 
00918 
00919                 // A little tweak to remain backward compatible
00920                 // The $autoload['core'] item was deprecated
00921                 if ( ! isset($autoload['libraries']))
00922                 {
00923                         $autoload['libraries'] = $autoload['core'];
00924                 }
00925                 
00926                 // Load libraries
00927                 if (isset($autoload['libraries']) AND count($autoload['libraries']) > 0)
00928                 {
00929                         // Load the database driver.
00930                         if (in_array('database', $autoload['libraries']))
00931                         {
00932                                 $this->database();
00933                                 $autoload['libraries'] = array_diff($autoload['libraries'], array('database'));
00934                         }
00935 
00936                         // Load scaffolding
00937                         if (in_array('scaffolding', $autoload['libraries']))
00938                         {
00939                                 $this->scaffolding();
00940                                 $autoload['libraries'] = array_diff($autoload['libraries'], array('scaffolding'));
00941                         }
00942                 
00943                         // Load all other libraries
00944                         foreach ($autoload['libraries'] as $item)
00945                         {
00946                                 $this->library($item);
00947                         }
00948                 }               
00949 
00950                 // Autoload models
00951                 if (isset($autoload['model']))
00952                 {
00953                         $this->model($autoload['model']);
00954                 }
00955 
00956         }

Here is the call graph for this function:

Here is the caller graph for this function:

CI_Loader::_ci_init_class ( class,
prefix = '',
config = FALSE 
)

Instantiates a class.

private

Parameters:
string 
string 
Returns:
null

Definition at line 840 of file Loader.php.

References $CI, $class, $config, and get_instance().

Referenced by _ci_load_class().

00841         {       
00842                 $class = strtolower($class);
00843                 
00844                 // Is there an associated config file for this class?
00845                 if ($config === NULL)
00846                 {
00847                         if (file_exists(APPPATH.'config/'.$class.EXT))
00848                         {
00849                                 include_once(APPPATH.'config/'.$class.EXT);
00850                         }
00851                 }
00852                 
00853                 if ($prefix == '')
00854                 {
00855                         $name = (class_exists('CI_'.$class)) ? 'CI_'.$class : $class;
00856                 }
00857                 else
00858                 {
00859                         $name = $prefix.$class;
00860                 }
00861                 
00862                 // Set the variable name we will assign the class to    
00863                 $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class];
00864                                 
00865                 // Instantiate the class                
00866                 $CI =& get_instance();
00867                 if ($config !== NULL)
00868                 {
00869                         $CI->$classvar = new $name($config);
00870                 }
00871                 else
00872                 {               
00873                         $CI->$classvar = new $name;
00874                 }       
00875         }       

Here is the call graph for this function:

Here is the caller graph for this function:

CI_Loader::_ci_is_instance (  ) 

Determines whether we should use the CI instance or $this.

private

Returns:
bool

Definition at line 1018 of file Loader.php.

References $CI.

Referenced by _ci_assign_to_models(), and _ci_load().

01019         {
01020                 if ($this->_ci_is_php5 == TRUE)
01021                 {
01022                         return TRUE;
01023                 }
01024         
01025                 global $CI;
01026                 return (is_object($CI)) ? TRUE : FALSE;
01027         }

Here is the caller graph for this function:

CI_Loader::_ci_load ( _ci_data  ) 

Loader.

This function is used to load views and files. Variables are prefixed with _ci_ to avoid symbol collision with variables made available to view files

private

Parameters:
array 
Returns:
void

Definition at line 630 of file Loader.php.

References $OUT, _ci_is_instance(), config_item(), get_instance(), log_message(), and show_error().

Referenced by file(), and view().

00631         {
00632                 // Set the default data variables
00633                 foreach (array('_ci_view', '_ci_vars', '_ci_path', '_ci_return') as $_ci_val)
00634                 {
00635                         $$_ci_val = ( ! isset($_ci_data[$_ci_val])) ? FALSE : $_ci_data[$_ci_val];
00636                 }
00637 
00638                 // Set the path to the requested file
00639                 if ($_ci_path == '')
00640                 {
00641                         $_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION);
00642                         $_ci_file = ($_ci_ext == '') ? $_ci_view.EXT : $_ci_view;
00643                         $_ci_path = $this->_ci_view_path.$_ci_file;
00644                 }
00645                 else
00646                 {
00647                         $_ci_x = explode('/', $_ci_path);
00648                         $_ci_file = end($_ci_x);
00649                 }
00650                 
00651                 if ( ! file_exists($_ci_path))
00652                 {
00653                         show_error('Unable to load the requested file: '.$_ci_file);
00654                 }
00655         
00656                 // This allows anything loaded using $this->load (views, files, etc.)
00657                 // to become accessible from within the Controller and Model functions.
00658                 // Only needed when running PHP 5
00659                 
00660                 if ($this->_ci_is_instance())
00661                 {
00662                         $_ci_CI =& get_instance();
00663                         foreach (get_object_vars($_ci_CI) as $_ci_key => $_ci_var)
00664                         {
00665                                 if ( ! isset($this->$_ci_key))
00666                                 {
00667                                         $this->$_ci_key =& $_ci_CI->$_ci_key;
00668                                 }
00669                         }
00670                 }
00671 
00672                 /*
00673                  * Extract and cache variables
00674                  *
00675                  * You can either set variables using the dedicated $this->load_vars()
00676                  * function or via the second parameter of this function. We'll merge
00677                  * the two types and cache them so that views that are embedded within
00678                  * other views can have access to these variables.
00679                  */     
00680                 if (is_array($_ci_vars))
00681                 {
00682                         $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars);
00683                 }
00684                 extract($this->_ci_cached_vars);
00685                                 
00686                 /*
00687                  * Buffer the output
00688                  *
00689                  * We buffer the output for two reasons:
00690                  * 1. Speed. You get a significant speed boost.
00691                  * 2. So that the final rendered template can be
00692                  * post-processed by the output class.  Why do we
00693                  * need post processing?  For one thing, in order to
00694                  * show the elapsed page load time.  Unless we
00695                  * can intercept the content right before it's sent to
00696                  * the browser and then stop the timer it won't be accurate.
00697                  */
00698                 ob_start();
00699                                 
00700                 // If the PHP installation does not support short tags we'll
00701                 // do a little string replacement, changing the short tags
00702                 // to standard PHP echo statements.
00703                 
00704                 if ((bool) @ini_get('short_open_tag') === FALSE AND config_item('rewrite_short_tags') == TRUE)
00705                 {
00706                         echo eval('?>'.preg_replace("/;*\s*\?>/", "; ?>", str_replace('<?=', '<?php echo ', file_get_contents($_ci_path))));
00707                 }
00708                 else
00709                 {
00710                         include($_ci_path); // include() vs include_once() allows for multiple views with the same name
00711                 }
00712                 
00713                 log_message('debug', 'File loaded: '.$_ci_path);
00714                 
00715                 // Return the file data if requested
00716                 if ($_ci_return === TRUE)
00717                 {               
00718                         $buffer = ob_get_contents();
00719                         @ob_end_clean();
00720                         return $buffer;
00721                 }
00722 
00723                 /*
00724                  * Flush the buffer... or buff the flusher?
00725                  *
00726                  * In order to permit views to be nested within
00727                  * other views, we need to flush the content back out whenever
00728                  * we are beyond the first level of output buffering so that
00729                  * it can be seen and included properly by the first included
00730                  * template and any subsequent ones. Oy!
00731                  *
00732                  */     
00733                 if (ob_get_level() > $this->_ci_ob_level + 1)
00734                 {
00735                         ob_end_flush();
00736                 }
00737                 else
00738                 {
00739                         // PHP 4 requires that we use a global
00740                         global $OUT;
00741                         $OUT->append_output(ob_get_contents());
00742                         @ob_end_clean();
00743                 }
00744         }

Here is the call graph for this function:

Here is the caller graph for this function:

CI_Loader::_ci_load_class ( class,
params = NULL 
)

Load class.

This function loads the requested class.

private

Parameters:
string the item that is being loaded
mixed any additional parameters
Returns:
void

Definition at line 758 of file Loader.php.

References $class, _ci_init_class(), config_item(), log_message(), and show_error().

Referenced by library().

00759         {       
00760                 // Get the class name
00761                 $class = str_replace(EXT, '', $class);
00762 
00763                 // We'll test for both lowercase and capitalized versions of the file name
00764                 foreach (array(ucfirst($class), strtolower($class)) as $class)
00765                 {
00766                         $subclass = APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT;
00767 
00768                         // Is this a class extension request?                   
00769                         if (file_exists($subclass))
00770                         {
00771                                 $baseclass = BASEPATH.'libraries/'.ucfirst($class).EXT;
00772                                 
00773                                 if ( ! file_exists($baseclass))
00774                                 {
00775                                         log_message('error', "Unable to load the requested class: ".$class);
00776                                         show_error("Unable to load the requested class: ".$class);
00777                                 }
00778 
00779                                 // Safety:  Was the class already loaded by a previous call?
00780                                 if (in_array($subclass, $this->_ci_classes))
00781                                 {
00782                                         $is_duplicate = TRUE;
00783                                         log_message('debug', $class." class already loaded. Second attempt ignored.");
00784                                         return;
00785                                 }
00786         
00787                                 include_once($baseclass);                               
00788                                 include_once($subclass);
00789                                 $this->_ci_classes[] = $subclass;
00790         
00791                                 return $this->_ci_init_class($class, config_item('subclass_prefix'), $params);                  
00792                         }
00793                 
00794                         // Lets search for the requested library file and load it.
00795                         $is_duplicate = FALSE;          
00796                         for ($i = 1; $i < 3; $i++)
00797                         {
00798                                 $path = ($i % 2) ? APPPATH : BASEPATH;  
00799                                 $filepath = $path.'libraries/'.$class.EXT;
00800                                 
00801                                 // Does the file exist?  No?  Bummer...
00802                                 if ( ! file_exists($filepath))
00803                                 {
00804                                         continue;
00805                                 }
00806                                 
00807                                 // Safety:  Was the class already loaded by a previous call?
00808                                 if (in_array($filepath, $this->_ci_classes))
00809                                 {
00810                                         $is_duplicate = TRUE;
00811                                         log_message('debug', $class." class already loaded. Second attempt ignored.");
00812                                         return;
00813                                 }
00814                                 
00815                                 include_once($filepath);
00816                                 $this->_ci_classes[] = $filepath;
00817                                 return $this->_ci_init_class($class, '', $params);
00818                         }
00819                 } // END FOREACH
00820                 
00821                 // If we got this far we were unable to find the requested class.
00822                 // We do not issue errors if the load call failed due to a duplicate request
00823                 if ($is_duplicate == FALSE)
00824                 {
00825                         log_message('error', "Unable to load the requested class: ".$class);
00826                         show_error("Unable to load the requested class: ".$class);
00827                 }
00828         }

Here is the call graph for this function:

Here is the caller graph for this function:

CI_Loader::_ci_object_to_array ( object  ) 

Object to Array.

Takes an object as input and converts the class variables to array key/vals

private

Parameters:
object 
Returns:
array

Definition at line 1005 of file Loader.php.

Referenced by vars(), and view().

01006         {
01007                 return (is_object($object)) ? get_object_vars($object) : $object;
01008         }

Here is the caller graph for this function:

CI_Loader::CI_Loader (  ) 

Constructor.

Sets the path to the view files and gets the initial output buffering level

public

Definition at line 52 of file Loader.php.

References log_message().

Referenced by CI_Base::CI_Base().

00053         {       
00054                 $this->_ci_is_php5 = (floor(phpversion()) >= 5) ? TRUE : FALSE;
00055                 $this->_ci_view_path = APPPATH.'views/';
00056                 $this->_ci_ob_level  = ob_get_level();
00057                                 
00058                 log_message('debug', "Loader Class Initialized");
00059         }

Here is the call graph for this function:

Here is the caller graph for this function:

CI_Loader::config ( file = '',
use_sections = FALSE,
fail_gracefully = FALSE 
)

Loads a config file.

public

Parameters:
string 
Returns:
void

Definition at line 582 of file Loader.php.

References $CI, and get_instance().

00583         {                       
00584                 $CI =& get_instance();
00585                 $CI->config->load($file, $use_sections, $fail_gracefully);
00586         }

Here is the call graph for this function:

CI_Loader::database ( params = '',
return = FALSE,
active_record = FALSE 
)

Database Loader.

public

Parameters:
string the DB credentials
bool whether to return the DB object
bool whether to enable active record (this allows us to override the config setting)
Returns:
object

Definition at line 194 of file Loader.php.

References $active_record, $CI, _ci_assign_to_models(), DB(), and get_instance().

Referenced by _ci_autoloader(), dbforge(), and dbutil().

00195         {
00196                 // Grab the super object
00197                 $CI =& get_instance();
00198                 
00199                 // Do we even need to load the database class?
00200                 if (class_exists('CI_DB') AND $return == FALSE AND $active_record == FALSE AND isset($CI->db) AND is_object($CI->db))
00201                 {
00202                         return FALSE;
00203                 }       
00204         
00205                 require_once(BASEPATH.'database/DB'.EXT);
00206 
00207                 if ($return === TRUE)
00208                 {
00209                         return DB($params, $active_record);
00210                 }
00211                 
00212                 // Initialize the db variable.  Needed to prevent   
00213                 // reference errors with some configurations
00214                 $CI->db = '';
00215                 
00216                 // Load the DB class
00217                 $CI->db =& DB($params, $active_record); 
00218                 
00219                 // Assign the DB object to any existing models
00220                 $this->_ci_assign_to_models();
00221         }

Here is the call graph for this function:

Here is the caller graph for this function:

CI_Loader::dbforge (  ) 

Load the Database Forge Class.

public

Returns:
string

Definition at line 261 of file Loader.php.

References $CI, $class, database(), and get_instance().

00262         {
00263                 if ( ! class_exists('CI_DB'))
00264                 {
00265                         $this->database();
00266                 }
00267                 
00268                 $CI =& get_instance();
00269         
00270                 require_once(BASEPATH.'database/DB_forge'.EXT);
00271                 require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_forge'.EXT);
00272                 $class = 'CI_DB_'.$CI->db->dbdriver.'_forge';
00273 
00274                 $CI->dbforge = new $class();
00275                 
00276                 $CI->load->_ci_assign_to_models();
00277         }

Here is the call graph for this function:

CI_Loader::dbutil (  ) 

Load the Utilities Class.

public

Returns:
string

Definition at line 231 of file Loader.php.

References $CI, $class, database(), and get_instance().

00232         {
00233                 if ( ! class_exists('CI_DB'))
00234                 {
00235                         $this->database();
00236                 }
00237                 
00238                 $CI =& get_instance();
00239 
00240                 // for backwards compatibility, load dbforge so we can extend dbutils off it
00241                 // this use is deprecated and strongly discouraged
00242                 $CI->load->dbforge();
00243         
00244                 require_once(BASEPATH.'database/DB_utility'.EXT);
00245                 require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility'.EXT);
00246                 $class = 'CI_DB_'.$CI->db->dbdriver.'_utility';
00247 
00248                 $CI->dbutil =& new $class();
00249 
00250                 $CI->load->_ci_assign_to_models();
00251         }

Here is the call graph for this function:

CI_Loader::file ( path,
return = FALSE 
)

Load File.

This is a generic file loader

public

Parameters:
string 
bool 
Returns:
string

Definition at line 315 of file Loader.php.

References _ci_load().

00316         {
00317                 return $this->_ci_load(array('_ci_path' => $path, '_ci_return' => $return));
00318         }

Here is the call graph for this function:

CI_Loader::helper ( helpers = array()  ) 

Load Helper.

This function loads the specified helper file.

public

Parameters:
mixed 
Returns:
void

Definition at line 356 of file Loader.php.

References config_item(), log_message(), and show_error().

Referenced by helpers().

00357         {
00358                 if ( ! is_array($helpers))
00359                 {
00360                         $helpers = array($helpers);
00361                 }
00362         
00363                 foreach ($helpers as $helper)
00364                 {               
00365                         $helper = strtolower(str_replace(EXT, '', str_replace('_helper', '', $helper)).'_helper');
00366                 
00367                         if (isset($this->_ci_helpers[$helper]))
00368                         {
00369                                 continue;
00370                         }
00371                         
00372                         $ext_helper = APPPATH.'helpers/'.config_item('subclass_prefix').$helper.EXT;
00373 
00374                         // Is this a helper extension request?                  
00375                         if (file_exists($ext_helper))
00376                         {
00377                                 $base_helper = BASEPATH.'helpers/'.$helper.EXT;
00378                                 
00379                                 if ( ! file_exists($base_helper))
00380                                 {
00381                                         show_error('Unable to load the requested file: helpers/'.$helper.EXT);
00382                                 }
00383                                 
00384                                 include_once($ext_helper);
00385                                 include_once($base_helper);
00386                         }
00387                         elseif (file_exists(APPPATH.'helpers/'.$helper.EXT))
00388                         { 
00389                                 include_once(APPPATH.'helpers/'.$helper.EXT);
00390                         }
00391                         else
00392                         {               
00393                                 if (file_exists(BASEPATH.'helpers/'.$helper.EXT))
00394                                 {
00395                                         include_once(BASEPATH.'helpers/'.$helper.EXT);
00396                                 }
00397                                 else
00398                                 {
00399                                         show_error('Unable to load the requested file: helpers/'.$helper.EXT);
00400                                 }
00401                         }
00402 
00403                         $this->_ci_helpers[$helper] = TRUE;
00404                         
00405                 }
00406                 
00407                 log_message('debug', 'Helpers loaded: '.implode(', ', $helpers));
00408         }

Here is the call graph for this function:

Here is the caller graph for this function:

CI_Loader::helpers ( helpers = array()  ) 

Load Helpers.

This is simply an alias to the above function in case the user has written the plural form of this function.

public

Parameters:
array 
Returns:
void

Definition at line 422 of file Loader.php.

References helper().

00423         {
00424                 $this->helper($helpers);
00425         }

Here is the call graph for this function:

CI_Loader::language ( file = array(),
lang = '' 
)

Loads a language file.

public

Parameters:
array 
string 
Returns:
void

Definition at line 545 of file Loader.php.

References $CI, $lang, and get_instance().

00546         {
00547                 $CI =& get_instance();
00548 
00549                 if ( ! is_array($file))
00550                 {
00551                         $file = array($file);
00552                 }
00553 
00554                 foreach ($file as $langfile)
00555                 {       
00556                         $CI->lang->load($langfile, $lang);
00557                 }
00558         }

Here is the call graph for this function:

CI_Loader::library ( library = '',
params = NULL 
)

Class Loader.

This function lets users load and instantiate classes. It is designed to be called from a user's app controllers.

public

Parameters:
string the name of the class
mixed the optional parameters
Returns:
void

Definition at line 74 of file Loader.php.

References $class, _ci_assign_to_models(), and _ci_load_class().

Referenced by _ci_autoloader().

00075         {               
00076                 if ($library == '')
00077                 {
00078                         return FALSE;
00079                 }
00080 
00081                 if (is_array($library))
00082                 {
00083                         foreach ($library as $class)
00084                         {
00085                                 $this->_ci_load_class($class, $params);
00086                         }
00087                 }
00088                 else
00089                 {
00090                         $this->_ci_load_class($library, $params);
00091                 }
00092                 
00093                 $this->_ci_assign_to_models();
00094         }

Here is the call graph for this function:

Here is the caller graph for this function:

CI_Loader::model ( model,
name = '',
db_conn = FALSE 
)

Model Loader.

This function lets users load and instantiate models.

Parameters:
string the name of the class
string name for the model
bool database connection
Returns:
void

Definition at line 108 of file Loader.php.

References $CI, get_instance(), load_class(), and show_error().

Referenced by _ci_autoloader().

00109         {               
00110                 if (is_array($model))
00111                 {
00112                         foreach($model as $babe)
00113                         {
00114                                 $this->model($babe);    
00115                         }
00116                         return;
00117                 }
00118 
00119                 if ($model == '')
00120                 {
00121                         return;
00122                 }
00123         
00124                 // Is the model in a sub-folder? If so, parse out the filename and path.
00125                 if (strpos($model, '/') === FALSE)
00126                 {
00127                         $path = '';
00128                 }
00129                 else
00130                 {
00131                         $x = explode('/', $model);
00132                         $model = end($x);                       
00133                         unset($x[count($x)-1]);
00134                         $path = implode('/', $x).'/';
00135                 }
00136         
00137                 if ($name == '')
00138                 {
00139                         $name = $model;
00140                 }
00141                 
00142                 if (in_array($name, $this->_ci_models, TRUE))
00143                 {
00144                         return;
00145                 }
00146                 
00147                 $CI =& get_instance();
00148                 if (isset($CI->$name))
00149                 {
00150                         show_error('The model name you are loading is the name of a resource that is already being used: '.$name);
00151                 }
00152         
00153                 $model = strtolower($model);
00154                 
00155                 if ( ! file_exists(APPPATH.'models/'.$path.$model.EXT))
00156                 {
00157                         show_error('Unable to locate the model you have specified: '.$model);
00158                 }
00159                                 
00160                 if ($db_conn !== FALSE AND ! class_exists('CI_DB'))
00161                 {
00162                         if ($db_conn === TRUE)
00163                                 $db_conn = '';
00164                 
00165                         $CI->load->database($db_conn, FALSE, TRUE);
00166                 }
00167         
00168                 if ( ! class_exists('Model'))
00169                 {
00170                         load_class('Model', FALSE);
00171                 }
00172 
00173                 require_once(APPPATH.'models/'.$path.$model.EXT);
00174 
00175                 $model = ucfirst($model);
00176                                 
00177                 $CI->$name = new $model();
00178                 $CI->$name->_assign_libraries();
00179                 
00180                 $this->_ci_models[] = $name;    
00181         }

Here is the call graph for this function:

Here is the caller graph for this function:

CI_Loader::plugin ( plugins = array()  ) 

Load Plugin.

This function loads the specified plugin.

public

Parameters:
array 
Returns:
void

Definition at line 438 of file Loader.php.

References log_message(), and show_error().

Referenced by plugins().

00439         {
00440                 if ( ! is_array($plugins))
00441                 {
00442                         $plugins = array($plugins);
00443                 }
00444         
00445                 foreach ($plugins as $plugin)
00446                 {       
00447                         $plugin = strtolower(str_replace(EXT, '', str_replace('_pi', '', $plugin)).'_pi');              
00448 
00449                         if (isset($this->_ci_plugins[$plugin]))
00450                         {
00451                                 continue;
00452                         }
00453 
00454                         if (file_exists(APPPATH.'plugins/'.$plugin.EXT))
00455                         {
00456                                 include_once(APPPATH.'plugins/'.$plugin.EXT);   
00457                         }
00458                         else
00459                         {
00460                                 if (file_exists(BASEPATH.'plugins/'.$plugin.EXT))
00461                                 {
00462                                         include_once(BASEPATH.'plugins/'.$plugin.EXT);  
00463                                 }
00464                                 else
00465                                 {
00466                                         show_error('Unable to load the requested file: plugins/'.$plugin.EXT);
00467                                 }
00468                         }
00469                         
00470                         $this->_ci_plugins[$plugin] = TRUE;
00471                 }
00472                 
00473                 log_message('debug', 'Plugins loaded: '.implode(', ', $plugins));
00474         }

Here is the call graph for this function:

Here is the caller graph for this function:

CI_Loader::plugins ( plugins = array()  ) 

Load Plugins.

This is simply an alias to the above function in case the user has written the plural form of this function.

public

Parameters:
array 
Returns:
void

Definition at line 488 of file Loader.php.

References plugin().

00489         {
00490                 $this->plugin($plugins);
00491         }

Here is the call graph for this function:

CI_Loader::scaffold_language ( file = '',
lang = '',
return = FALSE 
)

Loads language files for scaffolding.

public

Parameters:
string 
Returns:
arra

Definition at line 567 of file Loader.php.

References $CI, $lang, and get_instance().

00568         {
00569                 $CI =& get_instance();
00570                 return $CI->lang->load($file, $lang, $return);
00571         }

Here is the call graph for this function:

CI_Loader::scaffolding ( table = ''  ) 

Scaffolding Loader.

This initializing function works a bit different than the others. It doesn't load the class. Instead, it simply sets a flag indicating that scaffolding is allowed to be used. The actual scaffolding function below is called by the front controller based on whether the second segment of the URL matches the "secret" scaffolding word stored in the application/config/routes.php

public

Parameters:
string 
Returns:
void

Definition at line 605 of file Loader.php.

References $CI, get_instance(), and show_error().

Referenced by _ci_autoloader().

00606         {               
00607                 if ($table === FALSE)
00608                 {
00609                         show_error('You must include the name of the table you would like to access when you initialize scaffolding');
00610                 }
00611                 
00612                 $CI =& get_instance();
00613                 $CI->_ci_scaffolding = TRUE;
00614                 $CI->_ci_scaff_table = $table;
00615         }

Here is the call graph for this function:

Here is the caller graph for this function:

CI_Loader::script ( scripts = array()  ) 

Load Script.

This function loads the specified include file from the application/scripts/ folder.

NOTE: This feature has been deprecated but it will remain available for legacy users.

public

Parameters:
array 
Returns:
void

Definition at line 508 of file Loader.php.

References log_message(), and show_error().

00509         {
00510                 if ( ! is_array($scripts))
00511                 {
00512                         $scripts = array($scripts);
00513                 }
00514         
00515                 foreach ($scripts as $script)
00516                 {       
00517                         $script = strtolower(str_replace(EXT, '', $script));
00518 
00519                         if (isset($this->_ci_scripts[$script]))
00520                         {
00521                                 continue;
00522                         }
00523                 
00524                         if ( ! file_exists(APPPATH.'scripts/'.$script.EXT))
00525                         {
00526                                 show_error('Unable to load the requested script: scripts/'.$script.EXT);
00527                         }
00528                         
00529                         include_once(APPPATH.'scripts/'.$script.EXT);
00530                 }
00531                 
00532                 log_message('debug', 'Scripts loaded: '.implode(', ', $scripts));
00533         }

Here is the call graph for this function:

CI_Loader::vars ( vars = array()  ) 

Set Variables.

Once variables are set they become available within the controller class and its "view" files.

public

Parameters:
array 
Returns:
void

Definition at line 332 of file Loader.php.

References _ci_object_to_array().

00333         {
00334                 $vars = $this->_ci_object_to_array($vars);
00335         
00336                 if (is_array($vars) AND count($vars) > 0)
00337                 {
00338                         foreach ($vars as $key => $val)
00339                         {
00340                                 $this->_ci_cached_vars[$key] = $val;
00341                         }
00342                 }
00343         }

Here is the call graph for this function:

CI_Loader::view ( view,
vars = array(),
return = FALSE 
)

Load View.

This function is used to load a "view" file. It has three parameters:

1. The name of the "view" file to be included. 2. An associative array of data to be extracted for use in the view. 3. TRUE/FALSE - whether to return the data or load it. In some cases it's advantageous to be able to return data so that a developer can process it in some way.

public

Parameters:
string 
array 
bool 
Returns:
void

Definition at line 298 of file Loader.php.

References _ci_load(), and _ci_object_to_array().

00299         {
00300                 return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
00301         }

Here is the call graph for this function:


Member Data Documentation

CI_Loader::$_ci_cached_vars = array()

Definition at line 36 of file Loader.php.

CI_Loader::$_ci_classes = array()

Definition at line 37 of file Loader.php.

CI_Loader::$_ci_helpers = array()

Definition at line 39 of file Loader.php.

CI_Loader::$_ci_is_instance = FALSE

Definition at line 35 of file Loader.php.

CI_Loader::$_ci_is_php5 = FALSE

Definition at line 34 of file Loader.php.

CI_Loader::$_ci_models = array()

Definition at line 38 of file Loader.php.

CI_Loader::$_ci_ob_level

Definition at line 32 of file Loader.php.

CI_Loader::$_ci_plugins = array()

Definition at line 40 of file Loader.php.

CI_Loader::$_ci_scripts = array()

Definition at line 41 of file Loader.php.

CI_Loader::$_ci_varmap = array('unit_test' => 'unit', 'user_agent' => 'agent')

Definition at line 42 of file Loader.php.

CI_Loader::$_ci_view_path = ''

Definition at line 33 of file Loader.php.


The documentation for this class was generated from the following file: