summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--application/config/routes.php14
-rw-r--r--application/controllers/Welcome.php (renamed from application/controllers/welcome.php)2
-rw-r--r--application/views/welcome_message.php2
-rwxr-xr-xindex.php4
-rw-r--r--system/core/CodeIgniter.php13
-rw-r--r--system/core/Loader.php112
-rw-r--r--system/core/Router.php56
-rw-r--r--system/helpers/form_helper.php2
-rw-r--r--system/libraries/Cache/Cache.php3
-rw-r--r--system/libraries/Form_validation.php4
-rw-r--r--system/libraries/User_agent.php19
-rw-r--r--tests/codeigniter/core/Loader_test.php32
-rw-r--r--user_guide_src/source/changelog.rst8
-rw-r--r--user_guide_src/source/general/cli.rst2
-rw-r--r--user_guide_src/source/general/controllers.rst10
-rw-r--r--user_guide_src/source/general/creating_libraries.rst7
-rw-r--r--user_guide_src/source/general/libraries.rst2
-rw-r--r--user_guide_src/source/general/models.rst9
-rw-r--r--user_guide_src/source/general/routing.rst14
-rw-r--r--user_guide_src/source/general/styleguide.rst31
-rw-r--r--user_guide_src/source/general/urls.rst18
-rw-r--r--user_guide_src/source/general/views.rst2
-rw-r--r--user_guide_src/source/helpers/smiley_helper.rst4
-rw-r--r--user_guide_src/source/installation/upgrade_300.rst86
-rw-r--r--user_guide_src/source/libraries/file_uploading.rst2
-rw-r--r--user_guide_src/source/libraries/loader.rst28
-rw-r--r--user_guide_src/source/libraries/migration.rst2
-rw-r--r--user_guide_src/source/libraries/xmlrpc.rst4
-rw-r--r--user_guide_src/source/tutorial/news_section.rst4
-rw-r--r--user_guide_src/source/tutorial/static_pages.rst2
30 files changed, 304 insertions, 194 deletions
diff --git a/application/config/routes.php b/application/config/routes.php
index a5047a14e..3078c3c76 100644
--- a/application/config/routes.php
+++ b/application/config/routes.php
@@ -49,7 +49,7 @@
| RESERVED ROUTES
| -------------------------------------------------------------------------
|
-| There are two reserved routes:
+| There are three reserved routes:
|
| $route['default_controller'] = 'welcome';
|
@@ -62,10 +62,20 @@
| This route will tell the Router which controller/method to use if those
| provided in the URL cannot be matched to a valid route.
|
+| $route['translate_uri_dashes'] = FALSE;
+|
+| This is not exactly a route, but allows you to automatically route
+| controller and method names that contain dashes. '-' isn't a valid
+| class or method name character, so it requires translation.
+| When you set this option to TRUE, it will replace ALL dashes in the
+| controller and method URI segments.
+|
+| Examples: my-controller/index -> my_controller/index
+| my-controller/my-method -> my_controller/my_method
*/
-
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
+$route['translate_uri_dashes'] = FALSE;
/* End of file routes.php */
/* Location: ./application/config/routes.php */ \ No newline at end of file
diff --git a/application/controllers/welcome.php b/application/controllers/Welcome.php
index 2f0e358bc..31ceea948 100644
--- a/application/controllers/welcome.php
+++ b/application/controllers/Welcome.php
@@ -50,4 +50,4 @@ class Welcome extends CI_Controller {
}
/* End of file welcome.php */
-/* Location: ./application/controllers/welcome.php */ \ No newline at end of file
+/* Location: ./application/controllers/Welcome.php */ \ No newline at end of file
diff --git a/application/views/welcome_message.php b/application/views/welcome_message.php
index 3cc8b80aa..2466a83fc 100644
--- a/application/views/welcome_message.php
+++ b/application/views/welcome_message.php
@@ -104,7 +104,7 @@ defined('BASEPATH') OR exit('No direct script access allowed');
<code>application/views/welcome_message.php</code>
<p>The corresponding controller for this page is found at:</p>
- <code>application/controllers/welcome.php</code>
+ <code>application/controllers/Welcome.php</code>
<p>If you are exploring CodeIgniter for the very first time, you should start by reading the <a href="user_guide/">User Guide</a>.</p>
</div>
diff --git a/index.php b/index.php
index cfb003eb8..f93cadb9d 100755
--- a/index.php
+++ b/index.php
@@ -61,7 +61,7 @@ switch (ENVIRONMENT)
case 'testing':
case 'production':
- error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED ^ E_STRICT);
+ error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT);
ini_set('display_errors', 0);
break;
@@ -274,4 +274,4 @@ switch (ENVIRONMENT)
require_once BASEPATH.'core/CodeIgniter.php';
/* End of file index.php */
-/* Location: ./index.php */
+/* Location: ./index.php */ \ No newline at end of file
diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php
index 3fe5c0648..a026920a4 100644
--- a/system/core/CodeIgniter.php
+++ b/system/core/CodeIgniter.php
@@ -165,7 +165,6 @@ defined('BASEPATH') OR exit('No direct script access allowed');
* ------------------------------------------------------
*/
$RTR =& load_class('Router', 'core');
- $RTR->_set_routing();
// Set any routing overrides that may exist in the main index file
if (isset($routing))
@@ -241,12 +240,13 @@ defined('BASEPATH') OR exit('No direct script access allowed');
// Load the local application controller
// Note: The Router class automatically validates the controller path using the router->_validate_request().
// If this include fails it means that the default controller in the Routes.php file is not resolving to something valid.
- if ( ! file_exists(APPPATH.'controllers/'.$RTR->directory.$RTR->class.'.php'))
+ $class = ucfirst($RTR->class);
+ if ( ! file_exists(APPPATH.'controllers/'.$RTR->directory.$class.'.php'))
{
show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
}
- include(APPPATH.'controllers/'.$RTR->directory.$RTR->class.'.php');
+ include(APPPATH.'controllers/'.$RTR->directory.$class.'.php');
// Set a mark point for benchmarking
$BM->mark('loading_time:_base_classes_end');
@@ -258,9 +258,8 @@ defined('BASEPATH') OR exit('No direct script access allowed');
*
* None of the methods in the app controller or the
* loader class can be called via the URI, nor can
- * controller functions that begin with an underscore.
+ * controller methods that begin with an underscore.
*/
- $class = $RTR->class;
$method = $RTR->method;
if ( ! class_exists($class, FALSE) OR $method[0] === '_' OR method_exists('CI_Controller', $method))
@@ -272,6 +271,8 @@ defined('BASEPATH') OR exit('No direct script access allowed');
$method = 'index';
}
+ $class = ucfirst($class);
+
if ( ! class_exists($class, FALSE))
{
if ( ! file_exists(APPPATH.'controllers/'.$class.'.php'))
@@ -310,6 +311,8 @@ defined('BASEPATH') OR exit('No direct script access allowed');
$method = 'index';
}
+ $class = ucfirst($class);
+
if ( ! class_exists($class, FALSE))
{
if ( ! file_exists(APPPATH.'controllers/'.$class.'.php'))
diff --git a/system/core/Loader.php b/system/core/Loader.php
index 70a6b6fa6..1709c2db1 100644
--- a/system/core/Loader.php
+++ b/system/core/Loader.php
@@ -76,13 +76,6 @@ class CI_Loader {
protected $_ci_helper_paths = array(APPPATH, BASEPATH);
/**
- * List of loaded base classes
- *
- * @var array
- */
- protected $_base_classes = array(); // Set by the controller class
-
- /**
* List of cached variables
*
* @var array
@@ -120,6 +113,8 @@ class CI_Loader {
'user_agent' => 'agent'
);
+ // --------------------------------------------------------------------
+
/**
* Class constructor
*
@@ -129,7 +124,8 @@ class CI_Loader {
*/
public function __construct()
{
- $this->_ci_ob_level = ob_get_level();
+ $this->_ci_ob_level = ob_get_level();
+ $this->_ci_classes =& is_loaded();
log_message('debug', 'Loader Class Initialized');
}
@@ -147,7 +143,6 @@ class CI_Loader {
*/
public function initialize()
{
- $this->_base_classes =& is_loaded();
$this->_ci_autoloader();
}
@@ -165,7 +160,7 @@ class CI_Loader {
*/
public function is_loaded($class)
{
- return isset($this->_ci_classes[$class]) ? $this->_ci_classes[$class] : FALSE;
+ return array_search(ucfirst($class), $this->_ci_classes, TRUE);
}
// --------------------------------------------------------------------
@@ -183,7 +178,11 @@ class CI_Loader {
*/
public function library($library = '', $params = NULL, $object_name = NULL)
{
- if (is_array($library))
+ if (empty($library))
+ {
+ return;
+ }
+ elseif (is_array($library))
{
foreach ($library as $class)
{
@@ -193,11 +192,6 @@ class CI_Loader {
return;
}
- if ($library === '' OR isset($this->_base_classes[$library]))
- {
- return;
- }
-
if ($params !== NULL && ! is_array($params))
{
$params = NULL;
@@ -261,33 +255,32 @@ class CI_Loader {
show_error('The model name you are loading is the name of a resource that is already being used: '.$name);
}
- $model = strtolower($model);
-
- foreach ($this->_ci_model_paths as $mod_path)
+ if ($db_conn !== FALSE && ! class_exists('CI_DB', FALSE))
{
- if ( ! file_exists($mod_path.'models/'.$path.$model.'.php'))
+ if ($db_conn === TRUE)
{
- continue;
+ $db_conn = '';
}
- if ($db_conn !== FALSE && ! class_exists('CI_DB', FALSE))
- {
- if ($db_conn === TRUE)
- {
- $db_conn = '';
- }
+ $CI->load->database($db_conn, FALSE, TRUE);
+ }
- $CI->load->database($db_conn, FALSE, TRUE);
- }
+ if ( ! class_exists('CI_Model', FALSE))
+ {
+ load_class('Model', 'core');
+ }
+
+ $model = ucfirst(strtolower($model));
- if ( ! class_exists('CI_Model', FALSE))
+ foreach ($this->_ci_model_paths as $mod_path)
+ {
+ if ( ! file_exists($mod_path.'models/'.$path.$model.'.php'))
{
- load_class('Model', 'core');
+ continue;
}
require_once($mod_path.'models/'.$path.$model.'.php');
- $model = ucfirst($model);
$CI->$name = new $model();
$this->_ci_models[] = $name;
return;
@@ -1118,30 +1111,35 @@ class CI_Loader {
// Set the variable name we will assign the class to
// Was a custom class name supplied? If so we'll use it
- $class = strtolower($class);
-
- if ($object_name === NULL)
+ if (empty($object_name))
{
- $classvar = isset($this->_ci_varmap[$class]) ? $this->_ci_varmap[$class] : $class;
+ $object_name = strtolower($class);
+ if (isset($this->_ci_varmap[$object_name]))
+ {
+ $object_name = $this->_ci_varmap[$object_name];
+ }
}
- else
+
+ // Don't overwrite existing properties
+ $CI =& get_instance();
+ if (isset($CI->$object_name))
{
- $classvar = $object_name;
+ if ($CI->$object_name instanceof $name)
+ {
+ log_message('debug', $class." has already been instantiated as '".$object_name."'. Second attempt aborted.");
+ return;
+ }
+
+ show_error("Resource '".$object_name."' already exists and is not a ".$class." instance.");
}
// Save the class name and object name
- $this->_ci_classes[$class] = $classvar;
+ $this->_ci_classes[$object_name] = $class;
// Instantiate the class
- $CI =& get_instance();
- if ($config !== NULL)
- {
- $CI->$classvar = new $name($config);
- }
- else
- {
- $CI->$classvar = new $name();
- }
+ $CI->$object_name = isset($config)
+ ? new $name($config)
+ : new $name();
}
// --------------------------------------------------------------------
@@ -1198,6 +1196,15 @@ class CI_Loader {
}
}
+ // Autoload drivers
+ if (isset($autoload['drivers']))
+ {
+ foreach ($autoload['drivers'] as $item)
+ {
+ $this->driver($item);
+ }
+ }
+
// Load libraries
if (isset($autoload['libraries']) && count($autoload['libraries']) > 0)
{
@@ -1215,15 +1222,6 @@ class CI_Loader {
}
}
- // Autoload drivers
- if (isset($autoload['drivers']))
- {
- foreach ($autoload['drivers'] as $item)
- {
- $this->driver($item);
- }
- }
-
// Autoload models
if (isset($autoload['model']))
{
diff --git a/system/core/Router.php b/system/core/Router.php
index c86ab9c20..989ae542e 100644
--- a/system/core/Router.php
+++ b/system/core/Router.php
@@ -82,6 +82,18 @@ class CI_Router {
public $default_controller;
/**
+ * Translate URI dashes
+ *
+ * Determines whether dashes in controller & method segments
+ * should be automatically replaced by underscores.
+ *
+ * @var bool
+ */
+ public $translate_uri_dashes = FALSE;
+
+ // --------------------------------------------------------------------
+
+ /**
* Class constructor
*
* Runs the route mapping function.
@@ -92,6 +104,7 @@ class CI_Router {
{
$this->config =& load_class('Config', 'core');
$this->uri =& load_class('URI', 'core');
+ $this->_set_routing();
log_message('debug', 'Router Class Initialized');
}
@@ -105,7 +118,7 @@ class CI_Router {
*
* @return void
*/
- public function _set_routing()
+ protected function _set_routing()
{
// Are query strings enabled in the config file? Normally CI doesn't utilize query strings
// since URI segments are more search-engine friendly, but they can optionally be used.
@@ -143,12 +156,14 @@ class CI_Router {
include(APPPATH.'config/'.ENVIRONMENT.'/routes.php');
}
- $this->routes = (empty($route) OR ! is_array($route)) ? array() : $route;
- unset($route);
-
- // Set the default controller so we can display it in the event
- // the URI doesn't correlated to a valid controller.
- $this->default_controller = empty($this->routes['default_controller']) ? FALSE : $this->routes['default_controller'];
+ // Validate & get reserved routes
+ if (isset($route) && is_array($route))
+ {
+ isset($route['default_controller']) && $this->default_controller = $route['default_controller'];
+ isset($route['translate_uri_dashes']) && $this->translate_uri_dashes = $route['translate_uri_dashes'];
+ unset($route['default_controller'], $route['translate_uri_dashes']);
+ $this->routes = $route;
+ }
// Were there any query string segments? If so, we'll validate them and bail out since we're done.
if (count($segments) > 0)
@@ -191,8 +206,6 @@ class CI_Router {
$method = 'index';
}
- $this->set_class($class);
- $this->set_method($method);
$this->_set_request(array($class, $method));
// re-index the routed segments array so it starts with 1 rather than 0
@@ -221,8 +234,16 @@ class CI_Router {
return $this->_set_default_controller();
}
- $this->set_class($segments[0]);
+ if ($this->translate_uri_dashes === TRUE)
+ {
+ $segments[0] = str_replace('-', '_', $segments[0]);
+ if (isset($segments[1]))
+ {
+ $segments[1] = str_replace('-', '_', $segments[1]);
+ }
+ }
+ $this->set_class($segments[0]);
isset($segments[1]) OR $segments[1] = 'index';
$this->set_method($segments[1]);
@@ -249,13 +270,11 @@ class CI_Router {
return $segments;
}
- $temp = str_replace('-', '_', $segments[0]);
+ $test = ucfirst($this->translate_uri_dashes === TRUE ? str_replace('-', '_', $segments[0]) : $segments[0]);
// Does the requested controller exist in the root folder?
- if (file_exists(APPPATH.'controllers/'.$temp.'.php'))
+ if (file_exists(APPPATH.'controllers/'.$test.'.php'))
{
- $segments[0] = $temp;
- empty($segments[1]) OR $segments[1] = str_replace('-', '_', $segments[1]);
return $segments;
}
@@ -266,11 +285,10 @@ class CI_Router {
$this->set_directory(array_shift($segments));
if (count($segments) > 0)
{
- $segments[0] = str_replace('-', '_', $segments[0]);
- empty($segments[1]) OR $segments[1] = str_replace('-', '_', $segments[1]);
+ $test = ucfirst($this->translate_uri_dashes === TRUE ? str_replace('-', '_', $segments[0]) : $segments[0]);
- // Does the requested controller exist in the sub-folder?
- if ( ! file_exists(APPPATH.'controllers/'.$this->directory.$segments[0].'.php'))
+ // Does the requested controller exist in the sub-directory?
+ if ( ! file_exists(APPPATH.'controllers/'.$this->directory.$test.'.php'))
{
if ( ! empty($this->routes['404_override']))
{
@@ -287,7 +305,7 @@ class CI_Router {
{
// Is the method being specified in the route?
$segments = explode('/', $this->default_controller);
- if ( ! file_exists(APPPATH.'controllers/'.$this->directory.$segments[0].'.php'))
+ if ( ! file_exists(APPPATH.'controllers/'.$this->directory.ucfirst($segments[0]).'.php'))
{
$this->directory = '';
}
diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php
index 2002d4269..bc14df221 100644
--- a/system/helpers/form_helper.php
+++ b/system/helpers/form_helper.php
@@ -988,7 +988,7 @@ if ( ! function_exists('_get_validation_object'))
// We set this as a variable since we're returning by reference.
$return = FALSE;
- if (FALSE !== ($object = $CI->load->is_loaded('form_validation')))
+ if (FALSE !== ($object = $CI->load->is_loaded('Form_validation')))
{
if ( ! isset($CI->$object) OR ! is_object($CI->$object))
{
diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php
index e1089f755..537897eaf 100644
--- a/system/libraries/Cache/Cache.php
+++ b/system/libraries/Cache/Cache.php
@@ -106,7 +106,7 @@ class CI_Cache extends CI_Driver_Library {
isset($config['key_prefix']) && $this->key_prefix = $config['key_prefix'];
- if (isset($config['backup']) && in_array('cache_'.$config['backup'], $this->valid_drivers))
+ if (isset($config['backup']) && in_array($config['backup'], $this->valid_drivers))
{
$this->_backup_driver = $config['backup'];
}
@@ -123,6 +123,7 @@ class CI_Cache extends CI_Driver_Library {
else
{
// Backup is supported. Set it to primary.
+ log_message('debug', 'Cache adapter "'.$this->_adapter.'" is unavailable. Falling back to "'.$this->_backup_driver.'" backup adapter.');
$this->_adapter = $this->_backup_driver;
}
}
diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index 40ba01202..8b9bfa897 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -583,7 +583,7 @@ class CI_Form_validation {
// If the field is blank, but NOT required, no further tests are necessary
$callback = FALSE;
- if ( ! in_array('required', $rules) && $postdata === NULL)
+ if ( ! in_array('required', $rules) && ($postdata === NULL OR $postdata === ''))
{
// Before we bail out, does the rule contain a callback?
if (preg_match('/(callback_\w+(\[.*?\])?)/', implode(' ', $rules), $match))
@@ -598,7 +598,7 @@ class CI_Form_validation {
}
// Isset Test. Typically this rule will only apply to checkboxes.
- if ($postdata === NULL && $callback === FALSE)
+ if (($postdata === NULL OR $postdata === '') && $callback === FALSE)
{
if (in_array('isset', $rules, TRUE) OR in_array('required', $rules))
{
diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php
index 2f6f81909..50ac9be98 100644
--- a/system/libraries/User_agent.php
+++ b/system/libraries/User_agent.php
@@ -471,13 +471,24 @@ class CI_User_agent {
*/
public function is_referral()
{
- if (empty($_SERVER['HTTP_REFERER']))
+ static $result;
+
+ if ( ! isset($result))
{
- return FALSE;
+ if (empty($_SERVER['HTTP_REFERER']))
+ {
+ $result = FALSE;
+ }
+ else
+ {
+ $referer_host = @parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST);
+ $own_host = parse_url(config_item('base_url'), PHP_URL_HOST);
+
+ $result = ($referer_host && $referer_host !== $own_host);
+ }
}
- $referer = parse_url($_SERVER['HTTP_REFERER']);
- return ! (empty($referer['host']) && strpos(config_item('base_url'), $referer['host']) !== FALSE);
+ return $result;
}
// --------------------------------------------------------------------
diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php
index ac2656e75..9ad3ca6b9 100644
--- a/tests/codeigniter/core/Loader_test.php
+++ b/tests/codeigniter/core/Loader_test.php
@@ -28,7 +28,7 @@ class Loader_test extends CI_TestCase {
$this->ci_vfs_create(ucfirst($lib), '<?php class '.$class.' { }', $this->ci_base_root, 'libraries');
// Test is_loaded fail
- $this->assertFalse($this->load->is_loaded($lib));
+ $this->assertFalse($this->load->is_loaded(ucfirst($lib)));
// Test loading as an array.
$this->assertNull($this->load->library(array($lib)));
@@ -123,7 +123,7 @@ class Loader_test extends CI_TestCase {
$this->assertEquals($cfg, $this->ci_obj->$obj->config);
// Test is_loaded
- $this->assertEquals($obj, $this->load->is_loaded($lib));
+ $this->assertEquals($obj, $this->load->is_loaded(ucfirst($lib)));
}
// --------------------------------------------------------------------
@@ -181,16 +181,16 @@ class Loader_test extends CI_TestCase {
$this->ci_set_core_class('model', 'CI_Model');
// Create model in VFS
- $model = 'unit_test_model';
- $class = ucfirst($model);
- $content = '<?php class '.$class.' extends CI_Model {} ';
+ $model = 'Unit_test_model';
+ $content = '<?php class '.$model.' extends CI_Model {} ';
$this->ci_vfs_create($model, $content, $this->ci_app_root, 'models');
// Load model
$this->assertNull($this->load->model($model));
// Was the model class instantiated.
- $this->assertTrue(class_exists($class));
+ $this->assertTrue(class_exists($model));
+ $this->assertObjectHasAttribute($model, $this->ci_obj);
// Test no model given
$this->assertNull($this->load->model(''));
@@ -204,11 +204,10 @@ class Loader_test extends CI_TestCase {
$this->ci_core_class('model');
// Create modelin VFS
- $model = 'test_sub_model';
+ $model = 'Test_sub_model';
$base = 'CI_Model';
- $class = ucfirst($model);
$subdir = 'cars';
- $this->ci_vfs_create($model, '<?php class '.$class.' extends '.$base.' { }', $this->ci_app_root,
+ $this->ci_vfs_create($model, '<?php class '.$model.' extends '.$base.' { }', $this->ci_app_root,
array('models', $subdir));
// Load model
@@ -216,10 +215,10 @@ class Loader_test extends CI_TestCase {
$this->assertNull($this->load->model($subdir.'/'.$model, $name));
// Was the model class instantiated?
- $this->assertTrue(class_exists($class));
+ $this->assertTrue(class_exists($model));
$this->assertObjectHasAttribute($name, $this->ci_obj);
$this->assertAttributeInstanceOf($base, $name, $this->ci_obj);
- $this->assertAttributeInstanceOf($class, $name, $this->ci_obj);
+ $this->assertAttributeInstanceOf($model, $name, $this->ci_obj);
// Test name conflict
$obj = 'conflict';
@@ -237,7 +236,7 @@ class Loader_test extends CI_TestCase {
{
$this->setExpectedException(
'RuntimeException',
- 'CI Error: Unable to locate the model you have specified: ci_test_nonexistent_model.php'
+ 'CI Error: Unable to locate the model you have specified: Ci_test_nonexistent_model.php'
);
$this->load->model('ci_test_nonexistent_model.php');
@@ -481,9 +480,8 @@ class Loader_test extends CI_TestCase {
// Create model in VFS package path
$dir = 'testdir';
$path = APPPATH.$dir.'/';
- $model = 'automod';
- $mod_class = ucfirst($model);
- $this->ci_vfs_create($model, '<?php class '.$mod_class.' { }', $this->ci_app_root, array($dir, 'models'));
+ $model = 'Automod';
+ $this->ci_vfs_create($model, '<?php class '.$model.' { }', $this->ci_app_root, array($dir, 'models'));
// Create autoloader config
$cfg = array(
@@ -513,8 +511,8 @@ class Loader_test extends CI_TestCase {
$this->assertAttributeInstanceOf($drv_class, $drv, $this->ci_obj);
// Verify model
- $this->assertTrue(class_exists($mod_class), $mod_class.' does not exist');
- $this->assertAttributeInstanceOf($mod_class, $model, $this->ci_obj);
+ $this->assertTrue(class_exists($model), $model.' does not exist');
+ $this->assertAttributeInstanceOf($model, $model, $this->ci_obj);
// Verify config calls
$this->assertEquals($cfg['config'], $this->ci_obj->config->loaded);
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 0beffb568..08a8f0b38 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -19,6 +19,7 @@ Release Date: Not Released
- General Changes
- PHP 5.1.6 is no longer supported. CodeIgniter now requires PHP 5.2.4.
+ - Changed filenaming convention (class file names now must be Ucfirst and everything else in lowercase).
- ``$_SERVER['CI_ENV']`` can now be set to control the ``ENVIRONMENT`` constant.
- Added an optional backtrace to php-error template.
- Added Android to the list of user agents.
@@ -374,6 +375,8 @@ Release Date: Not Released
- ``$config['rewrite_short_tags']`` now has no effect when using PHP 5.4 as ``<?=`` will always be available.
- Changed method ``config()`` to return whatever ``CI_Config::load()`` returns instead of always being void.
- Added support for model aliasing on autoload.
+ - Changed method ``is_loaded()`` to ask for the (case sensitive) library name instead of its instance name.
+ - Removed ``$_base_classes`` property and unified all class data in ``$_ci_classes`` instead.
- :doc:`Input Library <libraries/input>` changes include:
@@ -414,7 +417,7 @@ Release Date: Not Released
- :doc:`URI Routing <general/routing>` changes include:
- Added possibility to route requests using callbacks.
- - Added possibility to use dashes in the controller and method URI segments (translated to underscores).
+ - Added a new reserved route (*translate_uri_dashes*) to allow usage of dashes in the controller and method URI segments.
- Deprecated methods ``fetch_directory()``, ``fetch_class()`` and ``fetch_method()`` in favor of their respective public properties.
- :doc:`Language Library <libraries/language>` changes include:
@@ -483,7 +486,7 @@ Bug fixes for 3.0
- Fixed a bug (#23, #1238) - delete_all() in the `Database Caching Library <database/caching>` used to delete .htaccess and index.html files, which is a potential security risk.
- Fixed a bug in :doc:`Trackback Library <libraries/trackback>` method validate_url() where it didn't actually do anything, due to input not being passed by reference.
- Fixed a bug (#11, #183, #863) - CI_Form_validation::_execute() silently continued to the next rule, if a rule method/function is not found.
-- Fixed a bug (#122) Where routed uri string was being reported incorrectly in sub-directories.
+- Fixed a bug (#122) - routed URI string was being reported incorrectly in sub-directories.
- Fixed a bug (#1242) - read_dir() in the :doc:`Zip Library <libraries/zip>` wasn't compatible with Windows.
- Fixed a bug (#306) - ODBC driver didn't have an _insert_batch() method, which resulted in fatal error being triggered when insert_batch() is used with it.
- Fixed a bug in MSSQL and SQLSrv's _truncate() where the TABLE keyword was missing.
@@ -595,6 +598,7 @@ Bug fixes for 3.0
- Fixed a bug (#2490) - :doc:`Database Class <database/queries>` method ``query()`` returning boolean instead of a result object for PostgreSQL-specific *INSERT INTO ... RETURNING* statements.
- Fixed a bug (#249) - :doc:`Cache Library <libraries/caching>` didn't properly handle Memcache(d) configurations with missing options.
- Fixed a bug (#180) - :php:func:`config_item()` didn't take into account run-time configuration changes.
+- Fixed a bug (#2551) - :doc:`Loader Library <libraries/loader>` method ``library()`` didn't properly check if a class that is being loaded already exits.
Version 2.1.4
=============
diff --git a/user_guide_src/source/general/cli.rst b/user_guide_src/source/general/cli.rst
index 998d2a907..4145d5ccc 100644
--- a/user_guide_src/source/general/cli.rst
+++ b/user_guide_src/source/general/cli.rst
@@ -33,7 +33,7 @@ Let's try it: Hello World!
==========================
Let's create a simple controller so you can see it in action. Using your
-text editor, create a file called tools.php, and put the following code
+text editor, create a file called Tools.php, and put the following code
in it::
<?php
diff --git a/user_guide_src/source/general/controllers.rst b/user_guide_src/source/general/controllers.rst
index 04f23276d..d8ef824fb 100644
--- a/user_guide_src/source/general/controllers.rst
+++ b/user_guide_src/source/general/controllers.rst
@@ -18,7 +18,7 @@ Consider this URI::
example.com/index.php/blog/
In the above example, CodeIgniter would attempt to find a controller
-named blog.php and load it.
+named Blog.php and load it.
**When a controller's name matches the first segment of a URI, it will
be loaded.**
@@ -27,7 +27,7 @@ Let's try it: Hello World!
==========================
Let's create a simple controller so you can see it in action. Using your
-text editor, create a file called blog.php, and put the following code
+text editor, create a file called Blog.php, and put the following code
in it::
<?php
@@ -41,6 +41,8 @@ in it::
Then save the file to your *application/controllers/* directory.
+.. important:: The file must be called 'Blog.php', with a capital 'B'.
+
Now visit the your site using a URL similar to this::
example.com/index.php/blog/
@@ -136,7 +138,7 @@ present, as will be the case when only your site root URL is requested.
To specify a default controller, open your **application/config/routes.php**
file and set this variable::
- $route['default_controller'] = 'blog';
+ $route['default_controller'] = 'Blog';
Where Blog is the name of the controller class you want used. If you now
load your main index.php file without specifying any URI segments you'll
@@ -272,7 +274,7 @@ and place your controller classes within them.
specify the folder. For example, let's say you have a controller located
here::
- application/controllers/products/shoes.php
+ application/controllers/products/Shoes.php
To call the above controller your URI will look something like this::
diff --git a/user_guide_src/source/general/creating_libraries.rst b/user_guide_src/source/general/creating_libraries.rst
index 4fc8ed72f..4beb600da 100644
--- a/user_guide_src/source/general/creating_libraries.rst
+++ b/user_guide_src/source/general/creating_libraries.rst
@@ -42,8 +42,7 @@ Naming Conventions
The Class File
==============
-Classes should have this basic prototype (Note: We are using the name
-Someclass purely as an example)::
+Classes should have this basic prototype::
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
@@ -56,6 +55,8 @@ Someclass purely as an example)::
/* End of file Someclass.php */
+.. note:: We are using the name Someclass purely as an example.
+
Using Your Class
================
@@ -81,7 +82,7 @@ constructor::
$params = array('type' => 'large', 'color' => 'red');
- $this->load->library('Someclass', $params);
+ $this->load->library('someclass', $params);
If you use this feature you must set up your class constructor to expect
data::
diff --git a/user_guide_src/source/general/libraries.rst b/user_guide_src/source/general/libraries.rst
index 6e1c8b6dd..9bbda51bb 100644
--- a/user_guide_src/source/general/libraries.rst
+++ b/user_guide_src/source/general/libraries.rst
@@ -29,4 +29,4 @@ Creating Your Own Libraries
===========================
Please read the section of the user guide that discusses how to
-:doc:`create your own libraries <creating_libraries>`.
+:doc:`create your own libraries <creating_libraries>`. \ No newline at end of file
diff --git a/user_guide_src/source/general/models.rst b/user_guide_src/source/general/models.rst
index a028a9569..c4fd12476 100644
--- a/user_guide_src/source/general/models.rst
+++ b/user_guide_src/source/general/models.rst
@@ -84,8 +84,7 @@ Where **Model_name** is the name of your class. Class names **must** have
the first letter capitalized with the rest of the name lowercase. Make
sure your class extends the base Model class.
-The file name will be a lower case version of your class name. For
-example, if your class is this::
+The file name must match the class name. For example, if this is your class::
class User_model extends CI_Model {
@@ -98,7 +97,7 @@ example, if your class is this::
Your file will be this::
- application/models/user_model.php
+ application/models/User_model.php
Loading a Model
===============
@@ -111,7 +110,7 @@ the following method::
If your model is located in a sub-directory, include the relative path
from your models directory. For example, if you have a model located at
-*application/models/blog/queries.php* you'll load it using::
+*application/models/blog/Queries.php* you'll load it using::
$this->load->model('blog/queries');
@@ -181,4 +180,4 @@ database. The following options for connecting are available to you:
$config['pconnect'] = FALSE;
$config['db_debug'] = TRUE;
- $this->load->model('Model_name', '', $config); \ No newline at end of file
+ $this->load->model('model_name', '', $config); \ No newline at end of file
diff --git a/user_guide_src/source/general/routing.rst b/user_guide_src/source/general/routing.rst
index 123257fc8..5520f59fe 100644
--- a/user_guide_src/source/general/routing.rst
+++ b/user_guide_src/source/general/routing.rst
@@ -145,7 +145,7 @@ routing rules to process the back-references. Example::
Reserved Routes
===============
-There are two reserved routes::
+There are three reserved routes::
$route['default_controller'] = 'welcome';
@@ -165,5 +165,17 @@ error page. It won't affect to the ``show_404()`` function, which will
continue loading the default *error_404.php* file at
*application/views/errors/error_404.php*.
+
+::
+
+ $route['translate_uri_dashes'] = FALSE;
+
+As evident by the boolean value, this is not exactly a route. This
+option enables you to automatically replace dashes ('-') with
+underscores in the controller and method URI segments, thus saving you
+additional route entries if you need to do that.
+This is required, because the dash isn't a valid class or method name
+character and would cause a fatal error if you try to use it.
+
.. important:: The reserved routes must come before any wildcard or
regular expression routes. \ No newline at end of file
diff --git a/user_guide_src/source/general/styleguide.rst b/user_guide_src/source/general/styleguide.rst
index 144b362f5..5613eabec 100644
--- a/user_guide_src/source/general/styleguide.rst
+++ b/user_guide_src/source/general/styleguide.rst
@@ -71,13 +71,42 @@ identify a file as being complete and not truncated.
echo "Here's my code!";
- /* End of file myfile.php */
+ /* End of file Myfile.php */
/* Location: ./system/modules/mymodule/myfile.php */
.. note:: There should be no empty line or newline character(s) following
the closing comments. If you happen to see one when
submitting a pull request, please check your IDE settings and fix it.
+File Naming
+===========
+
+Class files must be named in a Ucfirst-like manner, while any other file name
+(configurations, views, generic scripts, etc.) should be in all lowercase.
+
+**INCORRECT**::
+
+ somelibrary.php
+ someLibrary.php
+ SOMELIBRARY.php
+ Some_Library.php
+
+ Application_config.php
+ Application_Config.php
+ applicationConfig.php
+
+**CORRECT**::
+
+ Somelibrary.php
+ Some_library.php
+
+ applicationconfig.php
+ application_config.php
+
+Furthermore, class file names should match the name of the class itself.
+For example, if you have a class named `Myclass`, then its filename must
+be **Myclass.php**.
+
Class and Method Naming
=======================
diff --git a/user_guide_src/source/general/urls.rst b/user_guide_src/source/general/urls.rst
index d678e4a0a..ca44e2f4c 100644
--- a/user_guide_src/source/general/urls.rst
+++ b/user_guide_src/source/general/urls.rst
@@ -32,24 +32,6 @@ The :doc:`URI Library <../libraries/uri>` and the :doc:`URL Helper
with your URI data. In addition, your URLs can be remapped using the
:doc:`URI Routing <routing>` feature for more flexibility.
-Friendly URLs
-=============
-
-As you might guess, since there's a straight relationship between
-URI segments and the controller/method pair that's being called,
-those two determining segments must represent a valid class and
-method name.
-You may however also use dashes in the class/method-representing
-segments, and they will automatically be translated to underscores
-in order to be valid routed segments.
-
-For example::
-
- example.com/my-settings/change-password/
-
-The above example will route to the ``My_settings`` controller and
-its method ``change_password()``.
-
Removing the index.php file
===========================
diff --git a/user_guide_src/source/general/views.rst b/user_guide_src/source/general/views.rst
index 4b1ab3c34..2fc0cb2ca 100644
--- a/user_guide_src/source/general/views.rst
+++ b/user_guide_src/source/general/views.rst
@@ -45,7 +45,7 @@ Where name is the name of your view file.
.. note:: The .php file extension does not need to be specified
unless you use something other than .php.
-Now, open the controller file you made earlier called blog.php, and
+Now, open the controller file you made earlier called Blog.php, and
replace the echo statement with the view loading method::
<?php
diff --git a/user_guide_src/source/helpers/smiley_helper.rst b/user_guide_src/source/helpers/smiley_helper.rst
index 7069b465e..3925f8b1a 100644
--- a/user_guide_src/source/helpers/smiley_helper.rst
+++ b/user_guide_src/source/helpers/smiley_helper.rst
@@ -43,7 +43,7 @@ View as described.
The Controller
--------------
-In your `application/controllers/` folder, create a file called
+In your **application/controllers/** directory, create a file called
smileys.php and place the code below in it.
.. important:: Change the URL in the :php:func:`get_clickable_smileys()`
@@ -70,7 +70,7 @@ the :doc:`Table Class <../libraries/table>`::
}
-In your `application/views/` folder, create a file called `smiley_view.php`
+In your **application/views/** folder, create a file called **smiley_view.php**
and place this code in it::
<html>
diff --git a/user_guide_src/source/installation/upgrade_300.rst b/user_guide_src/source/installation/upgrade_300.rst
index b396d9acb..3e8307cfc 100644
--- a/user_guide_src/source/installation/upgrade_300.rst
+++ b/user_guide_src/source/installation/upgrade_300.rst
@@ -17,22 +17,63 @@ they will need to be made fresh in this new one.
.. note:: If you have any custom developed files in these folders please
make copies of them first.
+**************************************
+Step 2: Update your classes file names
+**************************************
+
+Starting with CodeIgniter 3.0, all class filenames (libraries, drivers, controllers
+and models) must be named in a Ucfirst-like manner or in other words - they must
+start with a capital letter.
+
+For example, if you have the following library file:
+
+ application/libraries/mylibrary.php
+
+... then you'll have to rename it to:
+
+ application/libraries/Mylibrary.php
+
+The same goes for driver libraries and extensions and/or overrides of CodeIgniter's
+own libraries and core classes.
+
+ application/libraries/MY_email.php
+ application/core/MY_log.php
+
+The above files should respectively be renamed to the following:
+
+ application/libraries/MY_Email.php
+ application/core/MY_Log.php
+
+Controllers:
+
+ application/controllers/welcome.php -> application/controllers/Welcome.php
+
+Models:
+
+ application/models/misc_model.php -> application/models/Misc_model.php
+
+Please note that this DOES NOT affect directories, configuration files, views,
+helpers, hooks and anything else - it is only applied to classes.
+
+You must now follow just one simple rule - class names in Ucfirst and everything else
+in lowercase.
+
********************************
-Step 2: Replace config/mimes.php
+Step 3: Replace config/mimes.php
********************************
This config file has been updated to contain more user mime-types, please copy
it to _application/config/mimes.php*.
**************************************************************
-Step 3: Remove $autoload['core'] from your config/autoload.php
+Step 4: Remove $autoload['core'] from your config/autoload.php
**************************************************************
Use of the ``$autoload['core']`` config array has been deprecated as of CodeIgniter 1.4.1 and is now removed.
Move any entries that you might have listed there to ``$autoload['libraries']`` instead.
***************************************************
-Step 4: Move your Log class overrides or extensions
+Step 5: Move your Log class overrides or extensions
***************************************************
The Log Class is considered as a "core" class and is now located in the
@@ -40,10 +81,10 @@ The Log Class is considered as a "core" class and is now located in the
or extensions to work, you need to move them to **application/core/**::
application/libraries/Log.php -> application/core/Log.php
- application/libraries/MY_Log.php -> application/core/MY_log.php
+ application/libraries/MY_Log.php -> application/core/MY_Log.php
*********************************************************
-Step 5: Convert your Session usage from library to driver
+Step 6: Convert your Session usage from library to driver
*********************************************************
When you load (or autoload) the Session library, you must now load it as a driver instead of a library. This means
@@ -67,7 +108,7 @@ standard for Drivers. Also beware that some functions which are not part of the
the drivers, so your extension may have to be broken down into separate library and driver class extensions.
***************************************
-Step 6: Update your config/database.php
+Step 7: Update your config/database.php
***************************************
Due to 3.0.0's renaming of Active Record to Query Builder, inside your `config/database.php`, you will
@@ -78,14 +119,14 @@ need to rename the `$active_record` variable to `$query_builder`
// $active_record = TRUE;
$query_builder = TRUE;
-*******************************
-Step 7: Move your errors folder
-*******************************
+*******************************************
+Step 8: Move your error templates directory
+*******************************************
In version 3.0.0, the errors folder has been moved from _application/errors* to _application/views/errors*.
*******************************************************
-Step 8: Update your config/routes.php containing (:any)
+Step 9: Update your config/routes.php containing (:any)
*******************************************************
Historically, CodeIgniter has always provided the **:any** wildcard in routing,
@@ -104,31 +145,6 @@ regular expression::
(.+) // matches ANYTHING
(:any) // matches any character, except for '/'
-*****************************************
-Step 9: Update your libraries' file names
-*****************************************
-
-CodeIgniter 3.0 only allows library file names to be named in a *ucfirst* manner
-(meaning that the first letter of the class name must be a capital). For example,
-if you have the following library file:
-
- application/libraries/mylibrary.php
-
-... then you'll have to rename it to:
-
- application/libraries/Mylibrary.php
-
-The same goes for driver libraries and extensions and/or overrides of CodeIgniter's
-own libraries and core classes.
-
- application/libraries/MY_email.php
- application/core/MY_log.php
-
-The above files should respectively be renamed to the following:
-
- application/libraries/MY_Email.php
- application/core/MY_Log.php
-
*****************************************************************************
Step 10: Check the calls to Array Helper's element() and elements() functions
*****************************************************************************
diff --git a/user_guide_src/source/libraries/file_uploading.rst b/user_guide_src/source/libraries/file_uploading.rst
index a92d3af34..a295d7427 100644
--- a/user_guide_src/source/libraries/file_uploading.rst
+++ b/user_guide_src/source/libraries/file_uploading.rst
@@ -83,7 +83,7 @@ place this code and save it to your **application/views/** directory::
The Controller
==============
-Using a text editor, create a controller called upload.php. In it, place
+Using a text editor, create a controller called Upload.php. In it, place
this code and save it to your **application/controllers/** directory::
<?php
diff --git a/user_guide_src/source/libraries/loader.rst b/user_guide_src/source/libraries/loader.rst
index b048f4881..19446a9c8 100644
--- a/user_guide_src/source/libraries/loader.rst
+++ b/user_guide_src/source/libraries/loader.rst
@@ -192,7 +192,7 @@ $this->load->model('model_name');
If your model is located in a subdirectory, include the relative path
from your models directory. For example, if you have a model located at
-application/models/blog/queries.php you'll load it using::
+application/models/blog/Queries.php you'll load it using::
$this->load->model('blog/queries');
@@ -261,6 +261,32 @@ $this->load->config('file_name')
This method is an alias of the :doc:`config file loading
method <config>`: ``$this->config->load()``
+$this->load->is_loaded('library_name')
+======================================
+
+The ``is_loaded()`` method allows you to check if a class has already
+been loaded or not.
+
+.. note:: The word "class" here refers to libraries and drivers.
+
+If the requested class has been loaded, the method returns its assigned
+name in the CI Super-object and FALSE if it's not::
+
+ $this->load->library('form_validation');
+ $this->load->is_loaded('Form_validation'); // returns 'form_validation'
+
+ $this->load->is_loaded('Nonexistent_library'); // returns FALSE
+
+.. important:: If you have more than one instance of a class (assigned to
+ different properties), then the first one will be returned.
+
+::
+
+ $this->load->library('form_validation', $config, 'fv');
+ $this->load->library('form_validation');
+
+ $this->load->is_loaded('Form_validation'); // returns 'fv'
+
Application "Packages"
======================
diff --git a/user_guide_src/source/libraries/migration.rst b/user_guide_src/source/libraries/migration.rst
index b734f5c34..9dc3c08da 100644
--- a/user_guide_src/source/libraries/migration.rst
+++ b/user_guide_src/source/libraries/migration.rst
@@ -86,7 +86,7 @@ Then in **application/config/migration.php** set **$config['migration_version']
Usage Example
*************
-In this example some simple code is placed in **application/controllers/migrate.php**
+In this example some simple code is placed in **application/controllers/Migrate.php**
to update the schema.::
<?php
diff --git a/user_guide_src/source/libraries/xmlrpc.rst b/user_guide_src/source/libraries/xmlrpc.rst
index a43c48837..d2d695ee3 100644
--- a/user_guide_src/source/libraries/xmlrpc.rst
+++ b/user_guide_src/source/libraries/xmlrpc.rst
@@ -296,7 +296,7 @@ Client to send a request to the Server and receive a response.
The Client
----------
-Using a text editor, create a controller called xmlrpc_client.php. In
+Using a text editor, create a controller called Xmlrpc_client.php. In
it, place this code and save it to your application/controllers/
folder::
@@ -337,7 +337,7 @@ folder::
The Server
----------
-Using a text editor, create a controller called xmlrpc_server.php. In
+Using a text editor, create a controller called Xmlrpc_server.php. In
it, place this code and save it to your application/controllers/
folder::
diff --git a/user_guide_src/source/tutorial/news_section.rst b/user_guide_src/source/tutorial/news_section.rst
index d7754e9f3..c21f4e6de 100644
--- a/user_guide_src/source/tutorial/news_section.rst
+++ b/user_guide_src/source/tutorial/news_section.rst
@@ -16,7 +16,7 @@ are the place where you retrieve, insert, and update information in your
database or other data stores. They represent your data.
Open up the application/models directory and create a new file called
-news_model.php and add the following code. Make sure you've configured
+News_model.php and add the following code. Make sure you've configured
your database properly as described
`here <../database/configuration.html>`_.
@@ -85,7 +85,7 @@ Now that the queries are written, the model should be tied to the views
that are going to display the news items to the user. This could be done
in our pages controller created earlier, but for the sake of clarity, a
new "news" controller is defined. Create the new controller at
-application/controllers/news.php.
+application/controllers/News.php.
::
diff --git a/user_guide_src/source/tutorial/static_pages.rst b/user_guide_src/source/tutorial/static_pages.rst
index 97c74601d..330a50ecf 100644
--- a/user_guide_src/source/tutorial/static_pages.rst
+++ b/user_guide_src/source/tutorial/static_pages.rst
@@ -20,7 +20,7 @@ match:
As URL schemes become more complex, this may change. But for now, this
is all we will need to know.
-Create a file at application/controllers/pages.php with the following
+Create a file at application/controllers/Pages.php with the following
code.
::