diff options
Diffstat (limited to 'user_guide_src')
18 files changed, 153 insertions, 82 deletions
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. :: |