From 20292311636837e120d205e470e41826820feb46 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 22 Jul 2013 14:29:10 +0300 Subject: Change class filenames to Ucfirst --- application/controllers/Welcome.php | 53 ++++++++++++++ application/controllers/welcome.php | 53 -------------- index.php | 2 +- system/core/CodeIgniter.php | 12 ++-- system/core/Loader.php | 31 ++++----- system/core/Router.php | 8 +-- user_guide_src/source/general/cli.rst | 2 +- user_guide_src/source/general/controllers.rst | 10 +-- .../source/general/creating_libraries.rst | 7 +- user_guide_src/source/general/libraries.rst | 2 +- user_guide_src/source/general/models.rst | 9 ++- user_guide_src/source/general/styleguide.rst | 31 ++++++++- user_guide_src/source/general/views.rst | 2 +- user_guide_src/source/helpers/smiley_helper.rst | 4 +- user_guide_src/source/installation/upgrade_300.rst | 80 +++++++++++++--------- user_guide_src/source/libraries/file_uploading.rst | 2 +- user_guide_src/source/libraries/loader.rst | 2 +- user_guide_src/source/libraries/migration.rst | 2 +- user_guide_src/source/libraries/xmlrpc.rst | 4 +- user_guide_src/source/tutorial/news_section.rst | 4 +- user_guide_src/source/tutorial/static_pages.rst | 2 +- 21 files changed, 185 insertions(+), 137 deletions(-) create mode 100644 application/controllers/Welcome.php delete mode 100644 application/controllers/welcome.php diff --git a/application/controllers/Welcome.php b/application/controllers/Welcome.php new file mode 100644 index 000000000..31ceea948 --- /dev/null +++ b/application/controllers/Welcome.php @@ -0,0 +1,53 @@ + + * @see http://codeigniter.com/user_guide/general/urls.html + */ + public function index() + { + $this->load->view('welcome_message'); + } +} + +/* End of file welcome.php */ +/* Location: ./application/controllers/Welcome.php */ \ No newline at end of file diff --git a/application/controllers/welcome.php b/application/controllers/welcome.php deleted file mode 100644 index 2f0e358bc..000000000 --- a/application/controllers/welcome.php +++ /dev/null @@ -1,53 +0,0 @@ - - * @see http://codeigniter.com/user_guide/general/urls.html - */ - public function index() - { - $this->load->view('welcome_message'); - } -} - -/* End of file welcome.php */ -/* Location: ./application/controllers/welcome.php */ \ No newline at end of file diff --git a/index.php b/index.php index e5f570e8b..f93cadb9d 100755 --- a/index.php +++ b/index.php @@ -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 c68266408..a026920a4 100644 --- a/system/core/CodeIgniter.php +++ b/system/core/CodeIgniter.php @@ -240,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'); @@ -257,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)) @@ -271,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')) @@ -309,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..535c9e4db 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -261,33 +261,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; diff --git a/system/core/Router.php b/system/core/Router.php index cc3916f86..989ae542e 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -270,8 +270,7 @@ class CI_Router { return $segments; } - $test = ($this->translate_uri_dashes === TRUE) - ? str_replace('-', '_', $segments[0]) : $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/'.$test.'.php')) @@ -286,8 +285,7 @@ class CI_Router { $this->set_directory(array_shift($segments)); if (count($segments) > 0) { - $test = ($this->translate_uri_dashes === TRUE) - ? str_replace('-', '_', $segments[0]) : $segments[0]; + $test = ucfirst($this->translate_uri_dashes === TRUE ? str_replace('-', '_', $segments[0]) : $segments[0]); // Does the requested controller exist in the sub-directory? if ( ! file_exists(APPPATH.'controllers/'.$this->directory.$test.'.php')) @@ -307,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/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:: '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 `. +:doc:`create your own 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/styleguide.rst b/user_guide_src/source/general/styleguide.rst index 144b362f5..1683b04cd 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/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:: `:: } -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:: diff --git a/user_guide_src/source/installation/upgrade_300.rst b/user_guide_src/source/installation/upgrade_300.rst index 6c5f5692d..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 @@ -43,7 +84,7 @@ or extensions to work, you need to move them to **application/core/**:: 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 @@ -79,13 +120,13 @@ need to rename the `$active_record` variable to `$query_builder` $query_builder = TRUE; ******************************************* -Step 7: Move your error templates directory +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:: 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'); 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.:: `_. @@ -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. :: -- cgit v1.2.3-24-g4f1b