diff options
author | admin <devnull@localhost> | 2006-09-28 08:50:16 +0200 |
---|---|---|
committer | admin <devnull@localhost> | 2006-09-28 08:50:16 +0200 |
commit | 33de9a144aad28763405f8ae2d5c59df5e929b4f (patch) | |
tree | e774e7aa9eb99b40979cf2b678aea333dc2de3a5 | |
parent | 2296fc3ca61b689a2a486d1d39346424c069dc25 (diff) |
31 files changed, 211 insertions, 296 deletions
diff --git a/system/application/config/autoload.php b/system/application/config/autoload.php index 245d36a7c..6a62cd652 100644 --- a/system/application/config/autoload.php +++ b/system/application/config/autoload.php @@ -37,7 +37,7 @@ | $autoload['libraries'] = array('database', 'session', 'xmlrpc'); */ -$autoload['libraries'] = array('database', 'calendar', 'dbutil', 'dbexport'); +$autoload['libraries'] = array('database', 'calendar'); /* diff --git a/system/application/config/routes.php b/system/application/config/routes.php index 8a1f8b166..468ff0ab5 100644 --- a/system/application/config/routes.php +++ b/system/application/config/routes.php @@ -33,7 +33,7 @@ | | $route['scaffolding_trigger'] = 'scaffolding'; | -| This route lets you set a "secret" word that will trigger the +| This route lets you se t a "secret" word that will trigger the | scaffolding feature for added security. Note: Scaffolding must be | enabled in the controller in which you intend to use it. | diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 05194503f..4ac03820a 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -50,7 +50,7 @@ set_magic_quotes_runtime(0); // Kill magic quotes * ------------------------------------------------------ */ -$BM =& _load_class('CI_Benchmark'); +$BM =& _load_class('Benchmark'); $BM->mark('code_igniter_start'); /* @@ -59,7 +59,7 @@ $BM->mark('code_igniter_start'); * ------------------------------------------------------ */ -$EXT =& _load_class('CI_Hooks'); +$EXT =& _load_class('Hooks'); /* * ------------------------------------------------------ @@ -74,9 +74,9 @@ $EXT->_call_hook('pre_system'); * ------------------------------------------------------ */ -$CFG =& _load_class('CI_Config'); -$RTR =& _load_class('CI_Router'); -$OUT =& _load_class('CI_Output'); +$CFG =& _load_class('Config'); +$RTR =& _load_class('Router'); +$OUT =& _load_class('Output'); /* * ------------------------------------------------------ @@ -98,9 +98,9 @@ if ($EXT->_call_hook('cache_override') === FALSE) * ------------------------------------------------------ */ -$IN =& _load_class('CI_Input'); -$URI =& _load_class('CI_URI'); -$LANG =& _load_class('CI_Language'); +$IN =& _load_class('Input'); +$URI =& _load_class('URI'); +$LANG =& _load_class('Language'); /* * ------------------------------------------------------ @@ -115,7 +115,7 @@ $LANG =& _load_class('CI_Language'); * */ -_load_class('CI_Loader', FALSE); +_load_class('Loader', FALSE); if (floor(phpversion()) < 5) { @@ -126,7 +126,7 @@ else require(BASEPATH.'codeigniter/Base5'.EXT); } -_load_class('CI_Controller', FALSE); +_load_class('Controller', FALSE); require(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT); diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index 885cca2f5..24e6042cc 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -32,42 +32,81 @@ /** * Class registry * -* +* This function acts as a singleton. If the requested class does not +* exist it is instantiated and set to a static variable. If it has +* previously been instantiated the variable is returned. +* * @access public * @return object */ function &_load_class($class, $instantiate = TRUE) { static $objects = array(); - - if ( ! isset($objects[$class])) + + // Does the class exist? If so, we're done... + if (isset($objects[$class])) { - if (FALSE !== strpos($class, 'CI_')) - { - if (file_exists(APPPATH.'libraries/'.str_replace('CI_', '', $class).EXT)) - { - require(APPPATH.'libraries/'.str_replace('CI_', '', $class).EXT); - } - else - { - require(BASEPATH.'libraries/'.str_replace('CI_', '', $class).EXT); - } - } + return $objects[$class]; + } - if ($instantiate == TRUE) + // This is a special case. It's a class in the Base5.php file + // which we don't need to load. We only instantiate it. + if ($class == 'Instance') + { + return $objects[$class] =& new $class(); + } + + // If the requested class does not exist in the application/libraries + // folder we'll load the native class from the system/libraries folder. + + $is_subclass = FALSE; + if ( ! file_exists(APPPATH.'libraries/'.$class.EXT)) + { + require(BASEPATH.'libraries/'.$class.EXT); + } + else + { + // A core class can either be extended or replaced by putting an + // identially named file in the application/libraries folder. + // We need to need to determine if the class being requested is + // a sub-class or an independent instance so we'll open the file, + // read the top portion of it. If the class extends the base class + // we need to load it's parent. If it doesn't extend the base we'll + // only load the requested class. + + // Note: I'm not thrilled with this approach since it requires us to + // read the file, but I can't think of any other way to allow classes + // to be extended on-the-fly. I did benchmark the difference with and + // without the file reading and I'm not seeing a perceptable difference. + + $fp = fopen(APPPATH.'libraries/'.$class.EXT, "rb"); + if (preg_match("/MY_".$class."\s+extends\s+CI_".$class."/", fread($fp, '8000'))) { - if ($class == 'CI_Controller') - $class = 'Controller'; - - $objects[$class] =& new $class(); + require(BASEPATH.'libraries/'.$class.EXT); + require(APPPATH.'libraries/'.$class.EXT); + $is_subclass = TRUE; } else { - $objects[$class] = TRUE; + require(APPPATH.'libraries/'.$class.EXT); } + fclose($fp); } + + if ($instantiate == FALSE) + { + return $objects[$class] = TRUE; + } + + if ($is_subclass == TRUE) + { + $name = 'MY_'.$class; + return $objects[$class] =& new $name(); + } + + $name = ($class != 'Controller') ? 'CI_'.$class : $class; - return $objects[$class]; + return $objects[$class] =& new $name(); } /** @@ -115,7 +154,7 @@ function &_get_config() */ function show_error($message) { - $error =& _load_class('CI_Exceptions'); + $error =& _load_class('Exceptions'); echo $error->show_error('An Error Was Encountered', $message); exit; } @@ -133,7 +172,7 @@ function show_error($message) */ function show_404($page = '') { - $error =& _load_class('CI_Exceptions'); + $error =& _load_class('Exceptions'); $error->show_404($page); exit; } @@ -158,7 +197,7 @@ function log_message($level = 'error', $message, $php_error = FALSE) return; } - $LOG =& _load_class('CI_Log'); + $LOG =& _load_class('Log'); $LOG->write_log($level, $message, $php_error); } @@ -191,7 +230,7 @@ function _exception_handler($severity, $message, $filepath, $line) return; } - $error =& _load_class('CI_Exceptions'); + $error =& _load_class('Exceptions'); // Should we display the error? // We'll get the current error_reporting level and add its bits diff --git a/system/database/DB_export.php b/system/database/DB_export.php index a2e3e3e4c..1704f0dfd 100644 --- a/system/database/DB_export.php +++ b/system/database/DB_export.php @@ -13,12 +13,6 @@ * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_DB_export', 'dbexport'); - // ------------------------------------------------------------------------ /** diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index a2469d059..764f10cb7 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -12,11 +12,6 @@ * @since Version 1.0 * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_DB_utility', 'dbutility'); // ------------------------------------------------------------------------ diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index d4f322d5f..792e023a8 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -227,9 +227,13 @@ class CI_DB_mysql_driver extends CI_DB { return $str; } - if (function_exists('mysql_escape_string')) + if (function_exists('mysql_real_escape_string')) { - return mysql_real_escape_string($str); + return mysql_real_escape_string($str, $this->conn_id); + } + elseif (function_exists('mysql_escape_string')) + { + return mysql_escape_string($str); } else { diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 63df0fe6f..b158cfefe 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -230,14 +230,7 @@ class CI_DB_mysqli_driver extends CI_DB { return $str; } - if (function_exists('mysql_escape_string')) - { - return mysqli_real_escape_string($this->conn_id, $str); - } - else - { - return addslashes($str); - } + return mysqli_real_escape_string($this->conn_id, $str); } // -------------------------------------------------------------------- diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php index 9dd9d4ac4..d8dd903e7 100644 --- a/system/libraries/Benchmark.php +++ b/system/libraries/Benchmark.php @@ -31,15 +31,6 @@ class CI_Benchmark { var $marker = array(); - /** - * Constructor - * - * @access public - */ - function CI_Benchmark() - { - } - // END CI_Benchmark() // -------------------------------------------------------------------- diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index bde98113a..8c7d95aa5 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -13,11 +13,6 @@ * @filesource */ -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Calendar'); - // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 56b4d6f90..aa7b87b00 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -32,8 +32,6 @@ class Controller extends CI_Base { var $_ci_models = array(); var $_ci_scaffolding = FALSE; var $_ci_scaff_table = FALSE; - var $_ci_last_handle = NULL; - var $_ci_last_params = NULL; /** * Constructor @@ -71,48 +69,6 @@ class Controller extends CI_Base { /** * Initialization Handler * - * Designed to be called from the class files themselves. - * See: http://www.codeigniter.com/user_guide/general/creating_libraries.html - * - * @access public - * @param string class name - * @param string variable name - * @param mixed any additional parameters - * @return void - */ - function init_class($class, $varname = '', $params = NULL) - { - // First figure out what variable we're going to assign the class to - if ($varname == '') - { - $varname = ( ! is_null($this->_ci_last_handle)) ? $this->_ci_last_handle : strtolower(str_replace('CI_', '', $class)); - } - - // Are there any parameters? - if ($params === NULL AND $this->_ci_last_params !== NULL) - { - $params = $this->_ci_last_params; - } - - // Instantiate the class - if ( ! is_null($params)) - { - $this->$varname = new $class($params); - } - else - { - $this->$varname = new $class; - } - - $this->_ci_last_params = NULL; - $this->_ci_last_handle = NULL; - } - - // -------------------------------------------------------------------- - - /** - * Initialization Handler - * * This function loads the requested class. * * @access private @@ -120,15 +76,21 @@ class Controller extends CI_Base { * @param mixed any additional parameters * @return void */ - function _ci_init_class($class, $params = NULL) + function _ci_load_class($class, $params = NULL) { // Prep the class name $class = strtolower(str_replace(EXT, '', $class)); - - // These are used by $this->init_class() above. - // They lets us dynamically set the object name and pass parameters - $this->_ci_last_handle = $class; - $this->_ci_last_params = $params; + + // Is this a class extension request? + if (substr($class, 0, 3) == 'my_') + { + $class = preg_replace("/my_(.+)/", "\\1", $class); + $extend = TRUE; + } + else + { + $extend = FALSE; + } // Does THIS file (Controller.php) contain an initialization // function that maps to the requested class? @@ -150,30 +112,101 @@ class Controller extends CI_Base { return TRUE; } - // Lets search for the requested library file and load it. - // We'll assume that the file we load contains a call to - // $obj->init_class() so that the class can get instantiated. - // For backward compatibility we'll test for filenames that are - // both uppercase and lower. - foreach (array(ucfirst($class), $class) as $filename) + // Are we extending one of the base classes? + if ($extend == TRUE) { - for ($i = 1; $i < 3; $i++) + // Load the requested library from the main system/libraries folder + if (file_exists(BASEPATH.'libraries/'.ucfirst($class).EXT)) { - $path = ($i % 2) ? APPPATH : BASEPATH; + include_once(BASEPATH.'libraries/'.ucfirst($class).EXT); + } - if (file_exists($path.'libraries/'.$filename.EXT)) + // Now look for a matching library + foreach (array(ucfirst($class), $class) as $filename) + { + if (file_exists(APPPATH.'libraries/'.$filename.EXT)) { - include_once($path.'libraries/'.$filename.EXT); - return TRUE; + include_once(APPPATH.'libraries/'.$filename.EXT); + } + } + + return $this->_ci_init_class($filename, 'MY_', $params); + } + else + { + // Lets search for the requested library file and load it. + // For backward compatibility we'll test for filenames that are + // both uppercase and lower. + foreach (array(ucfirst($class), $class) as $filename) + { + for ($i = 1; $i < 3; $i++) + { + $path = ($i % 2) ? APPPATH : BASEPATH; + + if (file_exists($path.'libraries/'.$filename.EXT)) + { + include_once($path.'libraries/'.$filename.EXT); + return $this->_ci_init_class($filename, '', $params); + } } } - } // If we got this far we were unable to find the requested class log_message('error', "Unable to load the requested class: ".$class); show_error("Unable to load the class: ".$class); } + + // -------------------------------------------------------------------- + + /** + * Instantiates a class + * + * @access private + * @param string + * @param string + * @return null + */ + function _ci_init_class($class, $prefix = '', $config = NULL) + { + // Is there an associated config file for this class? + + if ($config == NULL) + { + if (file_exists(APPPATH.'config/'.$class.EXT)) + { + include_once(APPPATH.'config/'.$class.EXT); + } + } + + if ($prefix == '') + { + $name = ( ! class_exists($class)) ? 'CI_'.$class : $class; + } + else + { + $name = $prefix.ucfirst($class); + } + + $remap = array( + 'DB_export' => 'dbexport', + 'DB_utility' => 'dbutility', + 'Encryption' => 'encrypt', + 'Unit_test' => 'unit' + ); + + $varname = ( ! isset($remap[$class])) ? $class : $remap[$class]; + + // Instantiate the class + if ($config !== NULL) + { + $this->$varname = new $name($config); + } + else + { + $this->$varname = new $name; + } + } // -------------------------------------------------------------------- @@ -305,7 +338,7 @@ class Controller extends CI_Base { { if ( ! in_array($item, $exceptions)) { - $this->_ci_init_class($item); + $this->_ci_load_class($item); } else { @@ -334,10 +367,10 @@ class Controller extends CI_Base { foreach (array('Config', 'Input', 'Benchmark', 'URI', 'Output') as $val) { $class = strtolower($val); - $this->$class =& _load_class('CI_'.$val); + $this->$class =& _load_class($val); } - $this->lang =& _load_class('CI_Language'); + $this->lang =& _load_class('Language'); // In PHP 4 the Controller class is a child of CI_Loader. // In PHP 5 we run it as its own class. @@ -529,7 +562,7 @@ class Controller extends CI_Base { } $this->_ci_init_database("", FALSE, TRUE); - $this->_ci_init_class('pagination'); + $this->_ci_load_class('pagination'); require_once(BASEPATH.'scaffolding/Scaffolding'.EXT); $this->scaff = new Scaffolding($this->_ci_scaff_table); $this->scaff->$method(); diff --git a/system/libraries/Email.php b/system/libraries/Email.php index fd3fb8f17..5b991d1fa 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -13,17 +13,6 @@ * @filesource */ -// INITIALIZE THE CLASS --------------------------------------------------- - -$config = array(); -if (file_exists(APPPATH.'config/email'.EXT)) -{ - include_once(APPPATH.'config/email'.EXT); -} - -$obj =& get_instance(); -$obj->init_class('CI_Email', 'email', $config); - // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 6a3ca17b0..abc769460 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -12,11 +12,6 @@ * @since Version 1.0 * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Encrypt'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Hooks.php b/system/libraries/Hooks.php index 7ff0592ff..69ca1a9f1 100644 --- a/system/libraries/Hooks.php +++ b/system/libraries/Hooks.php @@ -41,7 +41,7 @@ class CI_Hooks { { log_message('debug', "Hooks Class Initialized"); - $CFG =& _load_class('CI_Config'); + $CFG =& _load_class('Config'); // If hooks are not enabled in the config file // there is nothing else to do diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 4962760eb..18e3253f7 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -13,17 +13,6 @@ * @filesource */ -// INITIALIZE THE CLASS --------------------------------------------------- - -$config = array(); -if (file_exists(APPPATH.'config/image_lib'.EXT)) -{ - include_once(APPPATH.'config/image_lib'.EXT); -} - -$obj =& get_instance(); -$obj->init_class('CI_Image_lib', '', $config); - // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Input.php b/system/libraries/Input.php index dbf939b18..ad7b0c571 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -42,7 +42,7 @@ class CI_Input { */ function CI_Input() { - $CFG =& _load_class('CI_Config'); + $CFG =& _load_class('Config'); $this->use_xss_clean = ($CFG->item('global_xss_filtering') === TRUE) ? TRUE : FALSE; $this->allow_get_array = ($CFG->item('enable_query_strings') === TRUE) ? TRUE : FALSE; diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 90d824049..fff9e78d3 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -71,7 +71,7 @@ class CI_Loader { return; $obj =& get_instance(); - $obj->_ci_init_class($class, $param); + $obj->_ci_load_class($class, $param); $obj->_ci_assign_to_models(); } diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 5a158245f..1c3f0d604 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -237,8 +237,8 @@ class CI_Output { */ function _display_cache(&$CFG, &$RTR) { - $CFG =& _load_class('CI_Config'); - $RTR =& _load_class('CI_Router'); + $CFG =& _load_class('Config'); + $RTR =& _load_class('Router'); $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path'); diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index cd55d56e0..867d214fc 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -12,17 +12,6 @@ * @since Version 1.0 * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$config = array(); -if (file_exists(APPPATH.'config/pagination'.EXT)) -{ - include_once(APPPATH.'config/pagination'.EXT); -} - -$obj =& get_instance(); -$obj->init_class('CI_Pagination', '', $config); // ------------------------------------------------------------------------ diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index 76182271f..42e78b0ee 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -12,11 +12,6 @@ * @since Version 1.0 * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Parser'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 34a2512a6..c056530a3 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -33,6 +33,7 @@ class CI_Router { var $segments = array(); var $rsegments = array(); var $routes = array(); + var $error_routes = array(); var $class = ''; var $method = 'index'; var $directory = ''; @@ -47,7 +48,7 @@ class CI_Router { */ function CI_Router() { - $this->config =& _load_class('CI_Config'); + $this->config =& _load_class('Config'); $this->_set_route_mapping(); log_message('debug', "Router Class Initialized"); } @@ -87,8 +88,8 @@ class CI_Router { // Set the default controller so we can display it in the event // the URI doesn't correlated to a valid controller. - $this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']); - + $this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']); + // Fetch the complete URI string $this->uri_string = $this->_get_uri_string(); @@ -138,7 +139,6 @@ class CI_Router { // Re-index the segment array so that it starts with 1 rather than 0 $this->_reindex_segments(); } - // END _set_route_mapping() // -------------------------------------------------------------------- @@ -185,7 +185,6 @@ class CI_Router { // identical to $this->segments $this->rsegments = $segments; } - // END _compile_segments() // -------------------------------------------------------------------- @@ -240,7 +239,6 @@ class CI_Router { // Can't find the requested controller... show_404(); } - // END _validate_segments() // -------------------------------------------------------------------- /** @@ -280,7 +278,6 @@ class CI_Router { unset($this->rsegments[0]); } } - // END _reindex_segments() // -------------------------------------------------------------------- @@ -333,7 +330,6 @@ class CI_Router { return getenv($uri); } } - // END _get_uri_string() // -------------------------------------------------------------------- @@ -381,7 +377,6 @@ class CI_Router { return $parsed_uri; } - // END _parse_request_uri() // -------------------------------------------------------------------- @@ -403,7 +398,6 @@ class CI_Router { } return $str; } - // END _filter_uri() // -------------------------------------------------------------------- @@ -461,7 +455,6 @@ class CI_Router { // matching route so we'll set the site default route $this->_compile_segments($this->segments); } - // END set_method() // -------------------------------------------------------------------- @@ -476,7 +469,6 @@ class CI_Router { { $this->class = $class; } - // END set_class() // -------------------------------------------------------------------- @@ -490,7 +482,6 @@ class CI_Router { { return $this->class; } - // END fetch_class() // -------------------------------------------------------------------- @@ -505,7 +496,6 @@ class CI_Router { { $this->method = $method; } - // END set_method() // -------------------------------------------------------------------- @@ -519,7 +509,6 @@ class CI_Router { { return $this->method; } - // END fetch_method() // -------------------------------------------------------------------- @@ -534,7 +523,6 @@ class CI_Router { { $this->directory = $dir.'/'; } - // END set_directory() // -------------------------------------------------------------------- @@ -548,7 +536,6 @@ class CI_Router { { return $this->directory; } - // END fetch_directory() } // END Router Class diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 76acbfea9..28e469da7 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -12,11 +12,6 @@ * @since Version 1.0 * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Session'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index 9b6138453..8b6cce16d 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -12,11 +12,6 @@ * @since Version 1.0 * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->trackback =& new CI_Trackback(); // ------------------------------------------------------------------------ diff --git a/system/libraries/URI.php b/system/libraries/URI.php index 89ca42e44..80b112660 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -42,7 +42,7 @@ class CI_URI { */ function CI_URI() { - $this->router =& _load_class('CI_Router'); + $this->router =& _load_class('Router'); log_message('debug', "URI Class Initialized"); } diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 04c3c199b..b2f4bf8cd 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -13,11 +13,6 @@ * @filesource */ -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Unit_test'); - // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 3a6a6fc34..091c6c30d 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -12,17 +12,6 @@ * @since Version 1.0 * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$config = array(); -if (file_exists(APPPATH.'config/upload'.EXT)) -{ - include_once(APPPATH.'config/upload'.EXT); -} - -$obj =& get_instance(); -$obj->init_class('CI_Upload', '', $config); // ------------------------------------------------------------------------ diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 34cacd5d8..80ee6a533 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -12,11 +12,6 @@ * @since Version 1.0 * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Validation'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 24f79f2ba..f90785430 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -18,10 +18,6 @@ if ( ! function_exists('xml_parser_create')) show_error('Your PHP installation does not support XML'); } -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Xmlrpc'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index f41437342..b47104857 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -23,11 +23,6 @@ if ( ! class_exists('CI_Xmlrpc')) show_error('You must load the Xmlrpc class before loading the Xmlrpcs class in order to create a server.'); } -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Xmlrpcs'); - // ------------------------------------------------------------------------ /** diff --git a/user_guide/general/controllers.html b/user_guide/general/controllers.html index a197299d5..0bfe973e5 100644 --- a/user_guide/general/controllers.html +++ b/user_guide/general/controllers.html @@ -381,6 +381,7 @@ is a list of reserved names. Do not name your controller functions any of these <li>_ci_init_scaffolding</li>
<li>_ci_is_loaded</li>
<li>_ci_load</li>
+<li>_ci_load_class</li>
<li>_ci_scaffolding</li>
<li>_ci_set_view_path</li>
</ul>
diff --git a/user_guide/general/creating_libraries.html b/user_guide/general/creating_libraries.html index b047838be..a2d40f95d 100644 --- a/user_guide/general/creating_libraries.html +++ b/user_guide/general/creating_libraries.html @@ -63,14 +63,27 @@ Creating Libraries <h1>Creating Libraries</h1>
<p>When we use the term "Libraries" we are normally referring to the classes that are located in the <kbd>libraries</kbd>
-directory and described in the Class Reference of this user guide. In this case, however, we will instead describe how you can create your own libraries within
-your <dfn>application</dfn> directory in order to maintain separation between your local resources and the global framework resources.</p>
+directory and described in the Class Reference of this user guide. In this case, however, we will instead describe how you can create
+your own libraries within your <dfn>application/libraries</dfn> directory in order to maintain separation between your local resources
+and the global framework resources.</p>
+
+<p>As an added bonus, Code Igniter permits your libraries to <kbd>extend</kbd> native classes if you simply need to add some functionality
+to an existing library. Or you can even replace native libraries just by placing identically named versions in your <dfn>application/libraries</dfn> folder.
+
+<p>In summary:</p>
+
+<ul>
+<li>You can create entirely new libraries.</li>
+<li>You can extend native libraries.</li>
+<li>You can replace native libraries.</li>
+</ul>
+
+
<h2>Storage</h2>
<p>Your library classes should be placed within your <dfn>application/libraries</dfn> folder, as this is where Code Igniter will look for them when
-they are initialized. If your class is named identically to a native class from the <dfn>system/libraries</dfn> folder, your version
-will be used instead.</p>
+they are initialized.</p>
<h2>Naming Conventions</h2>
@@ -87,10 +100,6 @@ will be used instead.</p> <p>Classes should have this basic prototype (Note: We are using the name <kbd>Myclass</kbd> purely as an example):</p>
<code><?php if (!defined('BASEPATH')) exit('No direct script access allowed');<br />
-<br />
-// Initialize the class<br />
-$obj =& get_instance();<br />
-$obj->init_class('Myclass');
<br /><br />
class Myclass {<br />
<br />
@@ -101,15 +110,6 @@ class Myclass {<br /> ?></code>
-<p>You'll notice in the above example that the class is instantiated directly from the file itself using these two lines of code:</p>
-
-<code>$obj =& get_instance();<br />
-$obj->init_class(<kbd>'Myclass'</kbd>);</code>
-
-<p class="important">Make sure and submit your class name in the first parameter of the <kbd>$obj->init_class()</kbd> function. In the
-above example it is <kbd>Myclass</kbd></p>
-
-
<h2>Using Your Class</h2>
<p>From within any of your <a href="controllers.html">Controller</a> functions you can initialize your class using the standard:</p>
@@ -124,22 +124,6 @@ Code Igniter doesn't care.</p> <code>$this-><kbd>myclass</kbd>->some_function(); // Object instances will always be lower case
</code>
-<h2>Setting a Different Class Variable Name</h2>
-
-
-<p>If you would like the object variable ($this->myclass) set to a different name you can specify it when initializing your class. For
-example, let's initialize it as <kbd>foobar</kbd>:</p>
-
-<code>$obj =& get_instance();<br />
-$obj->init_class('Myclass', <kbd>'foobar'</kbd>);</code>
-
-<p>In the above example you would still load your class like this:</p>
-
-<code>$this->load->library('<kbd>Mclass</kbd>');</code>
-
-<p>But you would use it like this:<p>
-
-<code>$this-><kbd>foobar</kbd>->function();</code>
<h2>Passing Parameters When Initializing Your Class</h2>
@@ -169,25 +153,7 @@ class Myclass {<br /> }<br /><br />
?></code>
-<p>You can also pass parameters via the third parameter of the <dfn>$obj->init_class()</dfn> function:</p>
-
-<code><?php if (!defined('BASEPATH')) exit('No direct script access allowed');<br />
-<br />
-
-$params = array('type' => 'large', 'color' => 'red');<br /><br />
-
-// Initialize the class<br />
-$obj =& get_instance();<br />
-$obj->init_class('Myclass', 'myclass', $params);
-<br /><br />
-class Myclass {<br />
-<br />
- function Myclass($params)<br />
- {<br />
- // Do something with $params<br />
- }<br />
-}<br /><br />
-?></code>
+<p>You can also pass parameters stored in a config file. Simply create a config file named identically to the class filename.</p>
|