From 2a97c7db940e94a115dea863708f587e58d26be4 Mon Sep 17 00:00:00 2001 From: John Wright Date: Mon, 16 Jan 2012 15:09:19 -0800 Subject: It appears the Security class has been added to the system/core folder and is loaded automatically as well. Using $this->load->library('security'); in controllers currently returns FALSE, yet you might not notice because the Security class is already loaded. I discovered this because of a custom Loader class I was using returned an error when loading the Security class. --- user_guide_src/source/general/core_classes.rst | 1 + 1 file changed, 1 insertion(+) (limited to 'user_guide_src/source/general') diff --git a/user_guide_src/source/general/core_classes.rst b/user_guide_src/source/general/core_classes.rst index ac41407f7..4aa6693f7 100644 --- a/user_guide_src/source/general/core_classes.rst +++ b/user_guide_src/source/general/core_classes.rst @@ -31,6 +31,7 @@ time CodeIgniter runs: - Log - Output - Router +- Security - URI - Utf8 -- cgit v1.2.3-24-g4f1b From 7efad20597ef7e06f8cf837a9f40918d2d3f2727 Mon Sep 17 00:00:00 2001 From: Jamie Rumbelow Date: Sun, 19 Feb 2012 12:37:00 +0000 Subject: Renaming Active Record to Query Builder across the system --- user_guide_src/source/general/models.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'user_guide_src/source/general') diff --git a/user_guide_src/source/general/models.rst b/user_guide_src/source/general/models.rst index b816f958a..0156b0460 100644 --- a/user_guide_src/source/general/models.rst +++ b/user_guide_src/source/general/models.rst @@ -55,7 +55,7 @@ model class might look like:: } .. note:: The functions in the above example use the :doc:`Active - Record <../database/active_record>` database functions. + Record <../database/query_builder>` database functions. .. note:: For the sake of simplicity in this example we're using $_POST directly. This is generally bad practice, and a more common approach -- cgit v1.2.3-24-g4f1b From bb8ae01bff0fa7cb3b14fb5f1310d944c414cf81 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 20 Apr 2012 10:31:51 -0400 Subject: added suggested styleguide addition for future consistency --- user_guide_src/source/general/styleguide.rst | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'user_guide_src/source/general') diff --git a/user_guide_src/source/general/styleguide.rst b/user_guide_src/source/general/styleguide.rst index 2b91d1cc0..925954c03 100644 --- a/user_guide_src/source/general/styleguide.rst +++ b/user_guide_src/source/general/styleguide.rst @@ -149,7 +149,7 @@ months down the line. There is not a required format for comments, but the following are recommended. `DocBlock `_ -style comments preceding class and method declarations so they can be +style comments preceding class, method, and property declarations so they can be picked up by IDEs:: /** @@ -172,6 +172,17 @@ picked up by IDEs:: * @return string */ function xml_encode($str) + +:: + + /** + * Data for class manipulation + * + * @var array + */ + public $data + + Use single line comments within code, leaving a blank line between large comment blocks and code. -- cgit v1.2.3-24-g4f1b From 697b75e5296c4add2577db9099c235781fd34430 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sat, 2 Jun 2012 11:22:58 +0100 Subject: Changed example model name to follow the CI styleguide class naming conventions --- user_guide_src/source/general/models.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'user_guide_src/source/general') diff --git a/user_guide_src/source/general/models.rst b/user_guide_src/source/general/models.rst index 0156b0460..72acf77b4 100644 --- a/user_guide_src/source/general/models.rst +++ b/user_guide_src/source/general/models.rst @@ -16,7 +16,7 @@ blog. You might have a model class that contains functions to insert, update, and retrieve your blog data. Here is an example of what such a model class might look like:: - class Blogmodel extends CI_Model { + class Blog_model extends CI_Model { var $title = ''; var $content = ''; -- cgit v1.2.3-24-g4f1b From 149c07726bb60df65766a1046e695b1897652cc7 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sat, 2 Jun 2012 11:23:41 +0100 Subject: Changed load model examples to use lowercase model name. Fixes #1417 --- user_guide_src/source/general/models.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'user_guide_src/source/general') diff --git a/user_guide_src/source/general/models.rst b/user_guide_src/source/general/models.rst index 72acf77b4..87f63e416 100644 --- a/user_guide_src/source/general/models.rst +++ b/user_guide_src/source/general/models.rst @@ -104,7 +104,7 @@ Your models will typically be loaded and called from within your :doc:`controller ` functions. To load a model you will use the following function:: - $this->load->model('Model_name'); + $this->load->model('model_name'); If your model is located in a sub-folder, include the relative path from your models folder. For example, if you have a model located at @@ -115,14 +115,14 @@ application/models/blog/queries.php you'll load it using:: Once loaded, you will access your model functions using an object with the same name as your class:: - $this->load->model('Model_name'); + $this->load->model('model_name'); - $this->Model_name->function(); + $this->model_name->function(); If you would like your model assigned to a different object name you can specify it via the second parameter of the loading function:: - $this->load->model('Model_name', 'fubar'); + $this->load->model('model_name', 'fubar'); $this->fubar->function(); @@ -133,7 +133,7 @@ view:: function blog() { - $this->load->model('Blog'); + $this->load->model('blog'); $data['query'] = $this->Blog->get_last_ten_entries(); @@ -165,7 +165,7 @@ database. The following options for connecting are available to you: defined in your database config file will be used: :: - $this->load->model('Model_name', '', TRUE); + $this->load->model('model_name', '', TRUE); - You can manually pass database connectivity settings via the third parameter:: -- cgit v1.2.3-24-g4f1b From dda21f6abc76451997b12c07e6066aa49c2d423d Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Sun, 3 Jun 2012 10:36:36 -0500 Subject: Added support for $_SERVER['CI_ENV'] in index.php Remember this is entirely optional, nothing will change if you do not which to use Multiple Environments just like right now. If you DO set CI_ENV you can manipulate the switch that controls error reporting, etc, so set it to "production" on your live site to hide errors from users. If you don't require this logic you can remove it, or change it entirely to check HTTP_HOST for environment subdomains, or check IP address, etc. --- user_guide_src/source/general/environments.rst | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'user_guide_src/source/general') diff --git a/user_guide_src/source/general/environments.rst b/user_guide_src/source/general/environments.rst index 40725feba..fa1b096e2 100644 --- a/user_guide_src/source/general/environments.rst +++ b/user_guide_src/source/general/environments.rst @@ -11,10 +11,16 @@ when "live". The ENVIRONMENT Constant ======================== -By default, CodeIgniter comes with the environment constant set to +By default, CodeIgniter comes with the environment constant set to use +the value provided in ``$_SERVER['CI_ENV']``, otherwise defaults to 'development'. At the top of index.php, you will see:: - define('ENVIRONMENT', 'development'); + define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development'); + +This server variable can be set in your .htaccess file, or Apache +config using `SetEnv `_. +Alternative methods are available for nginx and other servers, or you can +remove this logic entirely and set the constant based on the HTTP_HOST or IP. In addition to affecting some basic framework behavior (see the next section), you may use this constant in your own development to -- cgit v1.2.3-24-g4f1b From 6ef498b49946ba74d610b3805fb908b163a7f03a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 5 Jun 2012 22:01:58 +0300 Subject: Added get_mimes() function to system/core/Commons.php.The MIMEs array from config/mimes.php is used by multiple core classes, libraries and helpers and each of them has implemented an own way of getting it, which is not needed and is hard to maintain. This also fixes issue #1411 --- user_guide_src/source/general/common_functions.rst | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'user_guide_src/source/general') diff --git a/user_guide_src/source/general/common_functions.rst b/user_guide_src/source/general/common_functions.rst index 70563b8d2..99126f900 100644 --- a/user_guide_src/source/general/common_functions.rst +++ b/user_guide_src/source/general/common_functions.rst @@ -79,3 +79,8 @@ html_escape($mixed) This function provides short cut for htmlspecialchars() function. It accepts string and array. To prevent Cross Site Scripting (XSS), it is very useful. + +get_mimes() +============= + +This function returns the MIMEs array from config/mimes.php. \ No newline at end of file -- cgit v1.2.3-24-g4f1b From df242193f3e785f4c9b802be3432f373fbc34a14 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 11 Jun 2012 16:16:49 +0300 Subject: Alter documentation on requirements for the SQLSRV driver --- user_guide_src/source/general/requirements.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'user_guide_src/source/general') diff --git a/user_guide_src/source/general/requirements.rst b/user_guide_src/source/general/requirements.rst index d97b7b4b2..d9edfba6d 100644 --- a/user_guide_src/source/general/requirements.rst +++ b/user_guide_src/source/general/requirements.rst @@ -4,5 +4,6 @@ Server Requirements - `PHP `_ version 5.2.4 or newer. - A Database is required for most web application programming. Current - supported databases are MySQL (5.1+), MySQLi, MS SQL, SQLSRV, Oracle, - PostgreSQL, SQLite, SQLite3, CUBRID, Interbase, ODBC and PDO. + supported databases are MySQL (5.1+), MySQLi, Oracle, PostgreSQL, + MS SQL, SQLSRV (SQL Server 2005+), SQLite, SQLite3, CUBRID, Interbase, + ODBC and PDO. -- cgit v1.2.3-24-g4f1b From ff3f7dea40e8fae81dd586b340d30d24154cf5ab Mon Sep 17 00:00:00 2001 From: vlakoff Date: Sat, 16 Jun 2012 14:21:32 +0200 Subject: Documentation: remaining PHP "var" declarations changed to "public" Since PHP 4 isn't supported anymore, let's clean up these few PHP "var" declarations which were remaining in the documentation. According to my checks, there is no more PHP "var" left. --- user_guide_src/source/general/models.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'user_guide_src/source/general') diff --git a/user_guide_src/source/general/models.rst b/user_guide_src/source/general/models.rst index 87f63e416..2e1e025ee 100644 --- a/user_guide_src/source/general/models.rst +++ b/user_guide_src/source/general/models.rst @@ -18,9 +18,9 @@ model class might look like:: class Blog_model extends CI_Model { - var $title = ''; - var $content = ''; - var $date = ''; + public $title = ''; + public $content = ''; + public $date = ''; function __construct() { -- cgit v1.2.3-24-g4f1b From d13803813b355fccb17dd4f148f43b7a20977781 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 25 Jun 2012 23:54:18 -0700 Subject: First pass at ToC remediation --- user_guide_src/source/general/welcome.rst | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 user_guide_src/source/general/welcome.rst (limited to 'user_guide_src/source/general') diff --git a/user_guide_src/source/general/welcome.rst b/user_guide_src/source/general/welcome.rst new file mode 100644 index 000000000..b28c3bcc2 --- /dev/null +++ b/user_guide_src/source/general/welcome.rst @@ -0,0 +1,32 @@ +###################### +Welcome to CodeIgniter +###################### + +CodeIgniter is an Application Development Framework - a toolkit - for +people who build web sites using PHP. Its goal is to enable you to +develop projects much faster than you could if you were writing code +from scratch, by providing a rich set of libraries for commonly needed +tasks, as well as a simple interface and logical structure to access +these libraries. CodeIgniter lets you creatively focus on your project +by minimizing the amount of code needed for a given task. + +*********************** +Who is CodeIgniter For? +*********************** + +CodeIgniter is right for you if: + +- You want a framework with a small footprint. +- You need exceptional performance. +- You need broad compatibility with standard hosting accounts that run + a variety of PHP versions and configurations. +- You want a framework that requires nearly zero configuration. +- You want a framework that does not require you to use the command + line. +- You want a framework that does not require you to adhere to + restrictive coding rules. +- You are not interested in large-scale monolithic libraries like PEAR. +- You do not want to be forced to learn a templating language (although + a template parser is optionally available if you desire one). +- You eschew complexity, favoring simple solutions. +- You need clear, thorough documentation. -- cgit v1.2.3-24-g4f1b From b94b91afc77bcc133ff282559015933602bb2d3f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 4 Jul 2012 12:32:14 +0300 Subject: Some user guide updates --- user_guide_src/source/general/models.rst | 61 ++++++++++++++++---------------- 1 file changed, 31 insertions(+), 30 deletions(-) (limited to 'user_guide_src/source/general') diff --git a/user_guide_src/source/general/models.rst b/user_guide_src/source/general/models.rst index 2e1e025ee..4e52a9648 100644 --- a/user_guide_src/source/general/models.rst +++ b/user_guide_src/source/general/models.rst @@ -72,10 +72,11 @@ The basic prototype for a model class is this:: class Model_name extends CI_Model { - function __construct() - { - parent::__construct(); - } + public function __construct() + { + parent::__construct(); + } + } Where **Model_name** is the name of your class. Class names **must** have @@ -87,10 +88,11 @@ example, if your class is this:: class User_model extends CI_Model { - function __construct() - { - parent::__construct(); - } + public function __construct() + { + parent::__construct(); + } + } Your file will be this:: @@ -102,7 +104,7 @@ Loading a Model Your models will typically be loaded and called from within your :doc:`controller ` functions. To load a model you will use -the following function:: +the following method:: $this->load->model('model_name'); @@ -112,33 +114,34 @@ application/models/blog/queries.php you'll load it using:: $this->load->model('blog/queries'); -Once loaded, you will access your model functions using an object with -the same name as your class:: +Once loaded, you will access your model methods using an object with the +same name as your class:: $this->load->model('model_name'); - $this->model_name->function(); + $this->model_name->method(); If you would like your model assigned to a different object name you can -specify it via the second parameter of the loading function:: +specify it via the second parameter of the loading method:: - $this->load->model('model_name', 'fubar'); + $this->load->model('model_name', 'foobar'); - $this->fubar->function(); + $this->foobar->method(); Here is an example of a controller, that loads a model, then serves a view:: class Blog_controller extends CI_Controller { - function blog() - { - $this->load->model('blog'); + public function blog() + { + $this->load->model('blog'); - $data['query'] = $this->Blog->get_last_ten_entries(); + $data['query'] = $this->Blog->get_last_ten_entries(); + + $this->load->view('blog', $data); + } - $this->load->view('blog', $data); - } } @@ -170,15 +173,13 @@ database. The following options for connecting are available to you: - You can manually pass database connectivity settings via the third parameter:: - $config['hostname'] = "localhost"; - $config['username'] = "myusername"; - $config['password'] = "mypassword"; - $config['database'] = "mydatabase"; - $config['dbdriver'] = "mysql"; - $config['dbprefix'] = ""; + $config['hostname'] = 'localhost'; + $config['username'] = 'myusername'; + $config['password'] = 'mypassword'; + $config['database'] = 'mydatabase'; + $config['dbdriver'] = 'mysqli'; + $config['dbprefix'] = ''; $config['pconnect'] = FALSE; $config['db_debug'] = TRUE; - $this->load->model('Model_name', '', $config); - - + $this->load->model('Model_name', '', $config); \ No newline at end of file -- cgit v1.2.3-24-g4f1b From cf168303ead21d1c8ad89af01458806e6be197fd Mon Sep 17 00:00:00 2001 From: Jonatas Miguel Date: Mon, 6 Aug 2012 17:10:17 +0100 Subject: Updated documentation --- user_guide_src/source/general/routing.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'user_guide_src/source/general') diff --git a/user_guide_src/source/general/routing.rst b/user_guide_src/source/general/routing.rst index 45950fc11..6bb5bdbc5 100644 --- a/user_guide_src/source/general/routing.rst +++ b/user_guide_src/source/general/routing.rst @@ -106,6 +106,16 @@ call the shirts controller class and the id_123 function. You can also mix and match wildcards with regular expressions. +Callbacks +========= + +If you are using PHP >= 5.3 you can use callbacks in place of the normal routing +rules to process the back-references. Example:: + + $route['products/([a-z]+)/edit/(\d+)'] = function($product_type, $id){ + return "catalog/product_edit/" . strtolower($product_type) . "/" . $id; + }; + Reserved Routes =============== -- cgit v1.2.3-24-g4f1b From f002c2a825ccf6785e3867b4ecb92fe6013d364f Mon Sep 17 00:00:00 2001 From: Jonatas Miguel Date: Thu, 30 Aug 2012 13:56:01 +0200 Subject: Corrected styling errors in documentation --- user_guide_src/source/general/routing.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'user_guide_src/source/general') diff --git a/user_guide_src/source/general/routing.rst b/user_guide_src/source/general/routing.rst index 6bb5bdbc5..0a16e13af 100644 --- a/user_guide_src/source/general/routing.rst +++ b/user_guide_src/source/general/routing.rst @@ -112,7 +112,8 @@ Callbacks If you are using PHP >= 5.3 you can use callbacks in place of the normal routing rules to process the back-references. Example:: - $route['products/([a-z]+)/edit/(\d+)'] = function($product_type, $id){ + $route['products/([a-z]+)/edit/(\d+)'] = function ($product_type, $id) + { return "catalog/product_edit/" . strtolower($product_type) . "/" . $id; }; -- cgit v1.2.3-24-g4f1b From 8f1cdd1904d9f8da9e9cbd383e4385740cc6951b Mon Sep 17 00:00:00 2001 From: Jonatas Miguel Date: Thu, 30 Aug 2012 13:57:54 +0200 Subject: Changed spaces to tabs where appropriate. --- user_guide_src/source/general/routing.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'user_guide_src/source/general') diff --git a/user_guide_src/source/general/routing.rst b/user_guide_src/source/general/routing.rst index 0a16e13af..edbc735c4 100644 --- a/user_guide_src/source/general/routing.rst +++ b/user_guide_src/source/general/routing.rst @@ -113,7 +113,7 @@ If you are using PHP >= 5.3 you can use callbacks in place of the normal routing rules to process the back-references. Example:: $route['products/([a-z]+)/edit/(\d+)'] = function ($product_type, $id) - { + { return "catalog/product_edit/" . strtolower($product_type) . "/" . $id; }; -- cgit v1.2.3-24-g4f1b From 5f733c4fd1369a185804cd7b6d27debc50ab1826 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Sat, 15 Sep 2012 10:48:17 +0200 Subject: Update reserved names documentation - EXT removed in 079fbfcde095230f304e889217f897031a948f61 - VIEWPATH added in 8eef9c77512d4fad5357d3cbda83b89f844d7d16 --- user_guide_src/source/general/reserved_names.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'user_guide_src/source/general') diff --git a/user_guide_src/source/general/reserved_names.rst b/user_guide_src/source/general/reserved_names.rst index 5ce7fc2ff..3354375c5 100644 --- a/user_guide_src/source/general/reserved_names.rst +++ b/user_guide_src/source/general/reserved_names.rst @@ -45,11 +45,11 @@ Constants --------- - ENVIRONMENT -- EXT - FCPATH - SELF - BASEPATH - APPPATH +- VIEWPATH - CI_VERSION - FILE_READ_MODE - FILE_WRITE_MODE -- cgit v1.2.3-24-g4f1b From 0130acee56626951e755eda74f3e5938df69280b Mon Sep 17 00:00:00 2001 From: Erocanti Date: Tue, 9 Oct 2012 02:53:58 -0500 Subject: Changed Lunix for Linux "Lunix" while going over cli docs. --- user_guide_src/source/general/cli.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'user_guide_src/source/general') diff --git a/user_guide_src/source/general/cli.rst b/user_guide_src/source/general/cli.rst index 7dc1ca319..649d5d548 100644 --- a/user_guide_src/source/general/cli.rst +++ b/user_guide_src/source/general/cli.rst @@ -52,7 +52,7 @@ Now normally you would visit the your site using a URL similar to this:: example.com/index.php/tools/message/to -Instead, we are going to open Terminal in Mac/Lunix or go to Run > "cmd" +Instead, we are going to open Terminal in Mac/Linux or go to Run > "cmd" in Windows and navigate to our CodeIgniter project. .. code-block:: bash -- cgit v1.2.3-24-g4f1b From 06e9d1d7a4c979a43f9f8fa437526b6c7a547cec Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 11 Oct 2012 16:31:01 +0300 Subject: [ci skip] Remove core from the description of libraries loaded by the autoloader --- user_guide_src/source/general/autoloader.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'user_guide_src/source/general') diff --git a/user_guide_src/source/general/autoloader.rst b/user_guide_src/source/general/autoloader.rst index 259a4987e..8ecc13cb6 100644 --- a/user_guide_src/source/general/autoloader.rst +++ b/user_guide_src/source/general/autoloader.rst @@ -9,7 +9,7 @@ application you should consider auto-loading them for convenience. The following items can be loaded automatically: -- Core classes found in the "libraries" folder +- Classes found in the "libraries" folder - Helper files found in the "helpers" folder - Custom config files found in the "config" folder - Language files found in the "system/language" folder -- cgit v1.2.3-24-g4f1b From 3fb026713013b60845c4cfe633a8a59a30b9c7dd Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 22 Oct 2012 16:48:01 +0300 Subject: Add is_https() as a common function --- user_guide_src/source/general/common_functions.rst | 26 +++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'user_guide_src/source/general') diff --git a/user_guide_src/source/general/common_functions.rst b/user_guide_src/source/general/common_functions.rst index 99126f900..f3d48ac91 100644 --- a/user_guide_src/source/general/common_functions.rst +++ b/user_guide_src/source/general/common_functions.rst @@ -7,7 +7,7 @@ defined, and are available to you at any point. These do not require loading any libraries or helpers. is_php('version_number') -========================== +======================== is_php() determines of the PHP version being used is greater than the supplied version_number. @@ -24,7 +24,7 @@ greater than the supplied version number. Returns FALSE if the installed version of PHP is lower than the supplied version number. is_really_writable('path/to/file') -==================================== +================================== is_writable() returns TRUE on Windows servers when you really can't write to the file as the OS reports to PHP as FALSE only if the @@ -44,7 +44,7 @@ recommended on platforms where this information may be unreliable. } config_item('item_key') -========================= +======================= The :doc:`Config library <../libraries/config>` is the preferred way of accessing configuration information, however config_item() can be used @@ -56,8 +56,8 @@ show_error('message'), show_404('page'), log_message('level', 'message') These are each outlined on the :doc:`Error Handling ` page. -set_status_header(code, 'text'); -================================ +set_status_header(code, 'text') +=============================== Permits you to manually set a server status header. Example:: @@ -68,19 +68,25 @@ Permits you to manually set a server status header. Example:: a full list of headers. remove_invisible_characters($str) -=================================== +================================= This function prevents inserting null characters between ascii characters, like Java\\0script. html_escape($mixed) -==================== +=================== -This function provides short cut for htmlspecialchars() function. It +This function provides short cut for ``htmlspecialchars()`` function. It accepts string and array. To prevent Cross Site Scripting (XSS), it is very useful. get_mimes() -============= +=========== -This function returns the MIMEs array from config/mimes.php. \ No newline at end of file +This function returns the MIMEs array *from config/mimes.php*. + +is_https() +========== + +Returns TRUE if a secure (HTTPS) connection is used and FALSE +in any other case (including non-HTTP requests). \ No newline at end of file -- cgit v1.2.3-24-g4f1b From a9d98ceae9ebec711af9801dce7e43e85d5dcdc1 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 23 Oct 2012 10:05:31 +0300 Subject: [ci skip] Add a note about routes.php not being a filter --- user_guide_src/source/general/routing.rst | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'user_guide_src/source/general') diff --git a/user_guide_src/source/general/routing.rst b/user_guide_src/source/general/routing.rst index 45950fc11..c03937070 100644 --- a/user_guide_src/source/general/routing.rst +++ b/user_guide_src/source/general/routing.rst @@ -47,11 +47,16 @@ segment of the URL, and a number is found in the second segment, the You can match literal values or you can use two wildcard types: **(:num)** will match a segment containing only numbers. - **(:any)** will match a segment containing any character. +**(:any)** will match a segment containing any character. .. note:: Routes will run in the order they are defined. Higher routes will always take precedence over lower ones. +.. note:: Route rules are not filters! Setting a rule of e.g. + 'foo/bar/(:num)' will not prevent controller *Foo* and method + *bar* to be called with a non-numeric value if that is a valid + route. + Examples ======== -- cgit v1.2.3-24-g4f1b From f837ed97b98f4e05b4cc55938c1e68bf947280d5 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 23 Oct 2012 11:10:59 +0300 Subject: [ci skip] Drop cheatsheets and quick_reference PDFs from the documentation (unmaintainable) --- user_guide_src/source/general/quick_reference.rst | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 user_guide_src/source/general/quick_reference.rst (limited to 'user_guide_src/source/general') diff --git a/user_guide_src/source/general/quick_reference.rst b/user_guide_src/source/general/quick_reference.rst deleted file mode 100644 index b9108a528..000000000 --- a/user_guide_src/source/general/quick_reference.rst +++ /dev/null @@ -1,11 +0,0 @@ -##################### -Quick Reference Chart -##################### - -For a PDF version of this chart, `click -here `_. - -.. figure:: ../images/ci_quick_ref.png - :align: center - :alt: - -- cgit v1.2.3-24-g4f1b From 7676c2d6761cb3cdeccf005c2a30140f0ba3ced5 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 30 Oct 2012 13:42:01 +0200 Subject: Fix issue #658 (:any wildcard matching slashes) --- user_guide_src/source/general/routing.rst | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'user_guide_src/source/general') diff --git a/user_guide_src/source/general/routing.rst b/user_guide_src/source/general/routing.rst index c03937070..a6332c90c 100644 --- a/user_guide_src/source/general/routing.rst +++ b/user_guide_src/source/general/routing.rst @@ -29,7 +29,7 @@ Setting your own routing rules Routing rules are defined in your application/config/routes.php file. In it you'll see an array called $route that permits you to specify your own routing criteria. Routes can either be specified using wildcards or -Regular Expressions +Regular Expressions. Wildcards ========= @@ -47,7 +47,11 @@ segment of the URL, and a number is found in the second segment, the You can match literal values or you can use two wildcard types: **(:num)** will match a segment containing only numbers. -**(:any)** will match a segment containing any character. +**(:any)** will match a segment containing any character (except for '/', which is the segment delimiter). + +.. note:: Wildcards are actually aliases for regular expressions, with + **:any** being translated to **[^/]+** and **:num** to **[0-9]+**, + respectively. .. note:: Routes will run in the order they are defined. Higher routes will always take precedence over lower ones. @@ -104,12 +108,28 @@ rules. Any valid regular expression is allowed, as are back-references. A typical RegEx route might look something like this:: - $route['products/([a-z]+)/(\d+)'] = "$1/id_$2"; + $route['products/([a-z]+)/(\d+)'] = '$1/id_$2'; In the above example, a URI similar to products/shirts/123 would instead -call the shirts controller class and the id_123 function. +call the shirts controller class and the id_123 method. + +With regular expressions, you can also catch a segment containing a +forward slash ('/'), which would usually represent the delimiter between +multiple segments. +For example, if a user accesses a password protected area of your web +application and you wish to be able to redirect them back to the same +page after they log in, you may find this example useful:: + + $route['login/(.+)'] = 'auth/login/$1'; + +That will call the auth controller class and its ``login()`` method, +passing everything contained in the URI after *login/* as a parameter. + +For those of you who don't know regular expressions and want to learn +more about them, `regular-expressions.info ` +might be a good starting point. -You can also mix and match wildcards with regular expressions. +..note:: You can also mix and match wildcards with regular expressions. Reserved Routes =============== -- cgit v1.2.3-24-g4f1b From d1097a1dc30f40c68bc4a5c89d3fadb295c55e56 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Nov 2012 19:55:42 +0200 Subject: Allow use of dashes in controller/method URI segments Supersedes PR #642 --- user_guide_src/source/general/routing.rst | 6 +++--- user_guide_src/source/general/urls.rst | 27 +++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 7 deletions(-) (limited to 'user_guide_src/source/general') diff --git a/user_guide_src/source/general/routing.rst b/user_guide_src/source/general/routing.rst index 43c181669..e6174cc0d 100644 --- a/user_guide_src/source/general/routing.rst +++ b/user_guide_src/source/general/routing.rst @@ -162,8 +162,8 @@ appear by default. This route indicates which controller class should be loaded if the requested controller is not found. It will override the default 404 error page. It won't affect to the show_404() function, which will -continue loading the default error_404.php file at -application/errors/error_404.php. +continue loading the default *error_404.php* file at +*application/errors/error_404.php*. .. important:: The reserved routes must come before any wildcard or - regular expression routes. + regular expression routes. \ No newline at end of file diff --git a/user_guide_src/source/general/urls.rst b/user_guide_src/source/general/urls.rst index 6b390b559..20f80632a 100644 --- a/user_guide_src/source/general/urls.rst +++ b/user_guide_src/source/general/urls.rst @@ -28,9 +28,28 @@ approach, usually represent:: #. The third, and any additional segments, represent the ID and any variables that will be passed to the controller. -The :doc:`URI Class <../libraries/uri>` and the :doc:`URL Helper <../helpers/url_helper>` contain functions that make it -easy to work with your URI data. In addition, your URLs can be remapped -using the :doc:`URI Routing ` feature for more flexibility. +The :doc:`URI Class <../libraries/uri>` and the :doc:`URL Helper <../helpers/url_helper>` +contain functions that make it easy to work with your URI data. In addition, +your URLs can be remapped using the :doc:`URI 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 =========================== @@ -94,4 +113,4 @@ active. Your controllers and functions will then be accessible using the .. note:: If you are using query strings you will have to build your own URLs, rather than utilizing the URL helpers (and other helpers that generate URLs, like some of the form helpers) as these are designed - to work with segment based URLs. + to work with segment based URLs. \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 7b18a3f268ba622cf938ac460d07bd58cb1eea06 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 4 Nov 2012 20:27:35 +0200 Subject: Fix #708 --- user_guide_src/source/general/common_functions.rst | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'user_guide_src/source/general') diff --git a/user_guide_src/source/general/common_functions.rst b/user_guide_src/source/general/common_functions.rst index f3d48ac91..7f327f00b 100644 --- a/user_guide_src/source/general/common_functions.rst +++ b/user_guide_src/source/general/common_functions.rst @@ -46,10 +46,14 @@ recommended on platforms where this information may be unreliable. config_item('item_key') ======================= -The :doc:`Config library <../libraries/config>` is the preferred way of -accessing configuration information, however config_item() can be used -to retrieve single keys. See Config library documentation for more -information. +The :doc:`Config Library <../libraries/config>` is the preferred way of +accessing configuration information, however ``config_item()`` can be used +to retrieve single keys. See :doc:`Config Library <../libraries/config>` +documentation for more information. + +.. important:: This function only returns values set in your configuration + files. It does not take into account config values that are + dynamically set at runtime. show_error('message'), show_404('page'), log_message('level', 'message') ======================================================================== -- cgit v1.2.3-24-g4f1b From 522c73623b46afc9082ac7c8af5c34bf1b4f47f4 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 5 Nov 2012 16:40:32 +0200 Subject: Revert usage of is_callable() in system/core/CodeIgniter.php Seems to be causing issues (see #1970). Also updated the Controller docs, mainly to include an important note related to #1967. --- user_guide_src/source/general/controllers.rst | 152 ++++++++++++++------------ 1 file changed, 81 insertions(+), 71 deletions(-) (limited to 'user_guide_src/source/general') diff --git a/user_guide_src/source/general/controllers.rst b/user_guide_src/source/general/controllers.rst index 6e5079419..150d2269c 100644 --- a/user_guide_src/source/general/controllers.rst +++ b/user_guide_src/source/general/controllers.rst @@ -67,21 +67,21 @@ This is **not** valid:: ?> Also, always make sure your controller extends the parent controller -class so that it can inherit all its functions. +class so that it can inherit all its methods. -Functions -========= +Methods +======= -In the above example the function name is index(). The "index" function +In the above example the method name is ``index()``. The "index" method is always loaded by default if the **second segment** of the URI is empty. Another way to show your "Hello World" message would be this:: example.com/index.php/blog/index/ -**The second segment of the URI determines which function in the +**The second segment of the URI determines which method in the controller gets called.** -Let's try it. Add a new function to your controller:: +Let's try it. Add a new method to your controller:: -Now load the following URL to see the comment function:: +Now load the following URL to see the comment method:: example.com/index.php/blog/comments/ You should see your new message. -Passing URI Segments to your Functions -====================================== +Passing URI Segments to your methods +==================================== If your URI contains more then two segments they will be passed to your -function as parameters. +method as parameters. For example, lets say you have a URI like this:: example.com/index.php/products/shoes/sandals/123 -Your function will be passed URI segments 3 and 4 ("sandals" and "123"):: +Your method will be passed URI segments 3 and 4 ("sandals" and "123"):: .. important:: If you are using the :doc:`URI Routing ` - feature, the segments passed to your function will be the re-routed + feature, the segments passed to your method will be the re-routed ones. Defining a Default Controller @@ -145,53 +145,53 @@ 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 see your Hello World message by default. -Remapping Function Calls -======================== +Remapping Method Calls +====================== As noted above, the second segment of the URI typically determines which -function in the controller gets called. CodeIgniter permits you to -override this behavior through the use of the _remap() function:: +method in the controller gets called. CodeIgniter permits you to override +this behavior through the use of the ``_remap()`` method:: public function _remap() { - // Some code here... + // Some code here... } -.. important:: If your controller contains a function named _remap(), +.. important:: If your controller contains a method named _remap(), it will **always** get called regardless of what your URI contains. It - overrides the normal behavior in which the URI determines which function - is called, allowing you to define your own function routing rules. + overrides the normal behavior in which the URI determines which method + is called, allowing you to define your own method routing rules. -The overridden function call (typically the second segment of the URI) -will be passed as a parameter to the _remap() function:: +The overridden method call (typically the second segment of the URI) will +be passed as a parameter to the ``_remap()`` method:: public function _remap($method) { - if ($method == 'some_method') - { - $this->$method(); - } - else - { - $this->default_method(); - } + if ($method == 'some_method') + { + $this->$method(); + } + else + { + $this->default_method(); + } } -Any extra segments after the method name are passed into _remap() as an +Any extra segments after the method name are passed into ``_remap()`` as an optional second parameter. This array can be used in combination with -PHP's `call_user_func_array `_ +PHP's `call_user_func_array() `_ to emulate CodeIgniter's default behavior. :: public function _remap($method, $params = array()) { - $method = 'process_'.$method; - if (method_exists($this, $method)) - { - return call_user_func_array(array($this, $method), $params); - } - show_404(); + $method = 'process_'.$method; + if (method_exists($this, $method)) + { + return call_user_func_array(array($this, $method), $params); + } + show_404(); } Processing Output @@ -199,29 +199,29 @@ Processing Output CodeIgniter has an output class that takes care of sending your final rendered data to the web browser automatically. More information on this -can be found in the :doc:`Views ` and :doc:`Output class <../libraries/output>` pages. In some cases, however, you -might want to post-process the finalized data in some way and send it to -the browser yourself. CodeIgniter permits you to add a function named -_output() to your controller that will receive the finalized output -data. +can be found in the :doc:`Views ` and :doc:`Output Class +<../libraries/output>` pages. In some cases, however, you might want to +post-process the finalized data in some way and send it to the browser +yourself. CodeIgniter permits you to add a method named ``_output()`` +to your controller that will receive the finalized output data. -.. important:: If your controller contains a function named _output(), - it will **always** be called by the output class instead of echoing the - finalized data directly. The first parameter of the function will - contain the finalized output. +.. important:: If your controller contains a method named _output(), it + will **always** be called by the output class instead of echoing + the finalized data directly. The first parameter of the method + will contain the finalized output. Here is an example:: public function _output($output) { - echo $output; + echo $output; } -.. note:: Please note that your _output() function will receive the data in its +.. note:: Please note that your _output() method will receive the data in its finalized state. Benchmark and memory usage data will be rendered, cache files written (if you have caching enabled), and headers will be sent (if you use that :doc:`feature <../libraries/output>`) before it is - handed off to the _output() function. + handed off to the _output() method. To have your controller's output cached properly, its _output() method can use:: @@ -236,23 +236,27 @@ Here is an example:: output *before* any of the final processing is done, please see the available methods in the :doc:`Output Class <../libraries/output>`. -Private Functions -================= +Private methods +=============== -In some cases you may want certain functions hidden from public access. -To make a function private, simply add an underscore as the name prefix -and it will not be served via a URL request. For example, if you were to -have a function like this:: +In some cases you may want certain methods hidden from public access. +In order to achieve this, simply declare the method as being private +or protected and it will not be served via a URL request. For example, +if you were to have a method like this:: private function _utility() { - // some code + // some code } Trying to access it via the URL, like this, will not work:: example.com/index.php/blog/_utility/ +.. note:: Prefixing method names with an underscore will also prevent + them from being called. This is a legacy feature that is left + for backwards-compatibility. + Organizing Your Controllers into Sub-folders ============================================ @@ -297,11 +301,11 @@ manually call it. @@ -309,16 +313,22 @@ Constructors are useful if you need to set some default values, or run a default process when your class is instantiated. Constructors can't return a value, but they can do some default work. -Reserved Function Names -======================= +Reserved method names +===================== Since your controller classes will extend the main application -controller you must be careful not to name your functions identically to +controller you must be careful not to name your methods identically to the ones used by that class, otherwise your local functions will override them. See :doc:`Reserved Names ` for a full list. +.. important:: You should also never have a method named identically + to its class name. If you do, and there is no __construct() + method in the same class, then your e.g. Index::index() method + will be executed as a class constructor! This is a PHP4 + backwards-compatibility feature. + That's it! ========== -That, in a nutshell, is all there is to know about controllers. +That, in a nutshell, is all there is to know about controllers. \ No newline at end of file -- cgit v1.2.3-24-g4f1b From e9d2dc85b9cb255aae235635576972e4b7dbd5a8 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 7 Nov 2012 14:23:29 +0200 Subject: Added function_usable() to common functions It is now used to check whether dangerous functions like eval() and exec() are available. It appears that the Suhosin extension (which is becoming popular) terminates script execution instead of returning e.g. FALSE when it has a function blacklisted. function_exists() checks are insufficient and our only option is to check the ini settings here. Filed an issue here: https://github.com/stefanesser/suhosin/issues/18 ... hopefully we'll be able to deal with this in a more elegant way in the future. (this commit supersedes PR #1809) --- user_guide_src/source/general/common_functions.rst | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'user_guide_src/source/general') diff --git a/user_guide_src/source/general/common_functions.rst b/user_guide_src/source/general/common_functions.rst index 7f327f00b..22f8d1942 100644 --- a/user_guide_src/source/general/common_functions.rst +++ b/user_guide_src/source/general/common_functions.rst @@ -93,4 +93,17 @@ is_https() ========== Returns TRUE if a secure (HTTPS) connection is used and FALSE -in any other case (including non-HTTP requests). \ No newline at end of file +in any other case (including non-HTTP requests). + +function_usable($function_name) +=============================== + +Returns TRUE if a function exists and is usable, FALSE otherwise. + +This function runs a ``function_exists()`` check and if the +`Suhosin extension ` is loaded, +checks if it doesn't disable the function being checked. + +It is useful if you want to check for the availability of functions +such as ``eval()`` and ``exec()``, which are dangerous and might be +disabled on servers with highly restrictive security policies. \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 1bc30260d8bd35a958f3d7b899f68c95d69c9e75 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 9 Nov 2012 11:30:51 +0200 Subject: Polish the Common functions documentation --- user_guide_src/source/general/common_functions.rst | 150 ++++++++++++++++----- 1 file changed, 119 insertions(+), 31 deletions(-) (limited to 'user_guide_src/source/general') diff --git a/user_guide_src/source/general/common_functions.rst b/user_guide_src/source/general/common_functions.rst index 22f8d1942..66dabd95e 100644 --- a/user_guide_src/source/general/common_functions.rst +++ b/user_guide_src/source/general/common_functions.rst @@ -6,45 +6,62 @@ CodeIgniter uses a few functions for its operation that are globally defined, and are available to you at any point. These do not require loading any libraries or helpers. -is_php('version_number') -======================== +is_php() +======== -is_php() determines of the PHP version being used is greater than the -supplied version_number. +.. php:function:: is_php($version = '5.3.0') -:: + :param string $version: Version number + :returns: bool - if (is_php('5.3.0')) +Determines of the PHP version being used is greater than the +supplied version number. + +Example:: + + if (is_php('5.3')) { - $str = quoted_printable_encode($str); + $str = quoted_printable_encode($str); } Returns boolean TRUE if the installed version of PHP is equal to or greater than the supplied version number. Returns FALSE if the installed version of PHP is lower than the supplied version number. -is_really_writable('path/to/file') -================================== +is_really_writable() +==================== + +.. php:function:: is_really_writeable($file) -is_writable() returns TRUE on Windows servers when you really can't + :param string $file: File path + :returns: bool + +``is_writable()`` returns TRUE on Windows servers when you really can't write to the file as the OS reports to PHP as FALSE only if the -read-only attribute is marked. This function determines if a file is -actually writable by attempting to write to it first. Generally only -recommended on platforms where this information may be unreliable. +read-only attribute is marked. + +This function determines if a file is actually writable by attempting +to write to it first. Generally only recommended on platforms where +this information may be unreliable. -:: +Example:: if (is_really_writable('file.txt')) { - echo "I could write to this if I wanted to"; + echo "I could write to this if I wanted to"; } else { - echo "File is not writable"; + echo "File is not writable"; } -config_item('item_key') -======================= +config_item() +============= + +.. php:function:: config_item($key) + + :param string $key: Config item key + :returns: mixed The :doc:`Config Library <../libraries/config>` is the preferred way of accessing configuration information, however ``config_item()`` can be used @@ -55,14 +72,53 @@ documentation for more information. files. It does not take into account config values that are dynamically set at runtime. -show_error('message'), show_404('page'), log_message('level', 'message') -======================================================================== +show_error() +============ + +.. php:function:: show_error($message, $status_code, $heading = 'An Error Was Encountered') + + :param mixed $message: Error message + :param int $status_code: HTTP Response status code + :param string $heading: Error page heading + :returns: void + +This function calls ``CI_Exception::show_error()``. For more info, +please see the :doc:`Error Handling ` documentation. + +show_404() +========== + +.. php:function:: show_404($page = '', $log_error = TRUE) + + :param string $page: URI string + :param bool $log_error: Whether to log the error + :returns: void + +This function calls ``CI_Exception::show_404()``. For more info, +please see the :doc:`Error Handling ` documentation. + +log_message() +============= + +.. php:function:: log_message($level = 'error', $message, $php_error = FALSE) -These are each outlined on the :doc:`Error Handling ` page. + :param string $level: Log level + :param string $message: Message to log + :param bool $php_error: Whether we're loggin a native PHP error message + :returns: void -set_status_header(code, 'text') +This function is an alias for ``CI_Log::write_log()``. For more info, +please see the :doc:`Error Handling ` documentation. + +set_status_header() =============================== +.. php:function:: set_status_header($code, $text = '') + + :param int $code: HTTP Reponse status code + :param string $text: A custom message to set with the status code + :returns: void + Permits you to manually set a server status header. Example:: set_status_header(401); @@ -71,33 +127,65 @@ Permits you to manually set a server status header. Example:: `See here `_ for a full list of headers. -remove_invisible_characters($str) -================================= +remove_invisible_characters() +============================= + +.. php:function:: remove_invisible_characters($str, $url_encoded = TRUE) -This function prevents inserting null characters between ascii + :param string $str: Input string + :param bool $url_encoded: Whether to remove URL-encoded characters as well + :returns: string + +This function prevents inserting NULL characters between ASCII characters, like Java\\0script. -html_escape($mixed) -=================== +Example:: + + remove_invisible_characters('Java\\0script'); + // Returns: 'Javascript' + +html_escape() +============= + +.. php:function:: html_escape($var) -This function provides short cut for ``htmlspecialchars()`` function. It -accepts string and array. To prevent Cross Site Scripting (XSS), it is -very useful. + :param mixed $var: Variable to escape + (string or array) + :returns: mixed + +This function acts as an alias for PHP's native ``htmlspecialchars()`` +function, with the advantage of being able to accept an array of strings. + +It is useful in preventing Cross Site Scripting (XSS). get_mimes() =========== -This function returns the MIMEs array *from config/mimes.php*. +.. php:function:: get_mimes() + + :returns: array + +This function returns a *reference* to the MIMEs array from +*application/config/mimes.php*. is_https() ========== +.. php:function:: is_https() + + :returns: bool + Returns TRUE if a secure (HTTPS) connection is used and FALSE in any other case (including non-HTTP requests). function_usable($function_name) =============================== +.. php:function:: function_usable($function_name) + + :param string $function_name: Function name + :returns: bool + Returns TRUE if a function exists and is usable, FALSE otherwise. This function runs a ``function_exists()`` check and if the -- cgit v1.2.3-24-g4f1b From 16a704ce8a1449cbee22fb13bd32508c975fac9f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 9 Nov 2012 17:25:00 +0200 Subject: [ci skip] Polish docs in user_guide_src/source/general/ --- user_guide_src/source/general/alternative_php.rst | 21 +++-- .../source/general/ancillary_classes.rst | 61 +++++++++++--- user_guide_src/source/general/autoloader.rst | 18 ++-- user_guide_src/source/general/caching.rst | 30 +++---- user_guide_src/source/general/cli.rst | 14 ++-- user_guide_src/source/general/controllers.rst | 84 +++++++++---------- user_guide_src/source/general/core_classes.rst | 40 ++++----- user_guide_src/source/general/creating_drivers.rst | 5 +- .../source/general/creating_libraries.rst | 93 +++++++++++++-------- user_guide_src/source/general/credits.rst | 2 +- user_guide_src/source/general/drivers.rst | 16 ++-- user_guide_src/source/general/environments.rst | 6 +- user_guide_src/source/general/errors.rst | 66 ++++++++++----- user_guide_src/source/general/helpers.rst | 58 ++++++------- user_guide_src/source/general/hooks.rst | 73 ++++++++-------- user_guide_src/source/general/index.rst | 2 +- user_guide_src/source/general/libraries.rst | 23 ++--- user_guide_src/source/general/managing_apps.rst | 44 +++++----- user_guide_src/source/general/models.rst | 97 +++++++++++----------- user_guide_src/source/general/profiling.rst | 28 +++---- user_guide_src/source/general/requirements.rst | 14 +++- user_guide_src/source/general/reserved_names.rst | 41 ++++----- user_guide_src/source/general/routing.rst | 50 +++++------ user_guide_src/source/general/security.rst | 51 ++++++++---- user_guide_src/source/general/styleguide.rst | 42 +++++----- user_guide_src/source/general/urls.rst | 24 +++--- user_guide_src/source/general/views.rst | 53 ++++++------ user_guide_src/source/general/welcome.rst | 2 +- 28 files changed, 586 insertions(+), 472 deletions(-) (limited to 'user_guide_src/source/general') diff --git a/user_guide_src/source/general/alternative_php.rst b/user_guide_src/source/general/alternative_php.rst index 4dc857a50..418d2e6eb 100644 --- a/user_guide_src/source/general/alternative_php.rst +++ b/user_guide_src/source/general/alternative_php.rst @@ -17,12 +17,12 @@ Automatic Short Tag Support work on your server it might be that "short tags" are disabled in your PHP ini file. CodeIgniter will optionally rewrite short tags on-the-fly, allowing you to use that syntax even if your server doesn't support it. - This feature can be enabled in your config/config.php file. + This feature can be enabled in your *config/config.php* file. Please note that if you do use this feature, if PHP errors are encountered in your **view files**, the error message and line number will not be accurately shown. Instead, all errors will be shown as -eval() errors. +``eval()`` errors. Alternative Echos ================= @@ -39,13 +39,13 @@ Alternative Control Structures ============================== Controls structures, like if, for, foreach, and while can be written in -a simplified format as well. Here is an example using foreach:: +a simplified format as well. Here is an example using ``foreach``::
    -
  • +
  • @@ -60,17 +60,16 @@ Also notice that instead of using a semicolon after each structure Here is another example, using ``if``/``elseif``/``else``. Notice the colons:: - + -

    Hi Sally

    +

    Hi Sally

    - + -

    Hi Joe

    +

    Hi Joe

    -

    Hi unknown user

    - - +

    Hi unknown user

    + \ No newline at end of file diff --git a/user_guide_src/source/general/ancillary_classes.rst b/user_guide_src/source/general/ancillary_classes.rst index f7c87011b..a4befc7b3 100644 --- a/user_guide_src/source/general/ancillary_classes.rst +++ b/user_guide_src/source/general/ancillary_classes.rst @@ -7,31 +7,35 @@ controllers but have the ability to utilize all of CodeIgniter's resources. This is easily possible as you'll see. get_instance() -=============== +============== -**Any class that you instantiate within your controller functions can +.. php:function:: get_instance() + + :returns: object of class CI_Controller + +**Any class that you instantiate within your controller methods can access CodeIgniter's native resources** simply by using the -get_instance() function. This function returns the main CodeIgniter -object. +``get_instance()`` function. This function returns the main +CodeIgniter object. -Normally, to call any of the available CodeIgniter functions requires -you to use the $this construct:: +Normally, to call any of the available CodeIgniter methods requires +you to use the ``$this`` construct:: $this->load->helper('url'); $this->load->library('session'); $this->config->item('base_url'); // etc. -$this, however, only works within your controllers, your models, or your -views. If you would like to use CodeIgniter's classes from within your -own custom classes you can do so as follows: +``$this``, however, only works within your controllers, your models, +or your views. If you would like to use CodeIgniter's classes from +within your own custom classes you can do so as follows: First, assign the CodeIgniter object to a variable:: $CI =& get_instance(); Once you've assigned the object to a variable, you'll use that variable -*instead* of $this:: +*instead* of ``$this``:: $CI =& get_instance(); @@ -40,10 +44,45 @@ Once you've assigned the object to a variable, you'll use that variable $CI->config->item('base_url'); // etc. -.. note:: You'll notice that the above get_instance() function is being +.. note:: You'll notice that the above get_instance() ``function`` is being passed by reference:: $CI =& get_instance(); This is very important. Assigning by reference allows you to use the original CodeIgniter object rather than creating a copy of it. + +Furthermore, if you'll be using ``get_intance()`` inside anoter class, +then it would be better if you assign it to a property. This way, you +won't need to call ``get_instance()`` in every single method. + +Example:: + +class Example { + + protected $CI; + + // We'll use a constructor, as you can't directly call a function + // from a property definition. + public function __construct() + { + // Assign the CodeIgniter super-object + $this->CI =& get_instance(); + } + + public function foo() + { + $this->CI->load->helper('url'); + redirect(); + } + + public function bar() + { + $this->CI->config_item('base_url'); + } + +} + +In the above example, both methods ``foo()`` and ``bar()`` will work +after you instantiate the Example class, without the need to call +``get_instance()`` in each of them. \ No newline at end of file diff --git a/user_guide_src/source/general/autoloader.rst b/user_guide_src/source/general/autoloader.rst index 8ecc13cb6..e5cec723b 100644 --- a/user_guide_src/source/general/autoloader.rst +++ b/user_guide_src/source/general/autoloader.rst @@ -9,15 +9,15 @@ application you should consider auto-loading them for convenience. The following items can be loaded automatically: -- Classes found in the "libraries" folder -- Helper files found in the "helpers" folder -- Custom config files found in the "config" folder -- Language files found in the "system/language" folder -- Models found in the "models" folder +- Classes found in the *libraries/* directory +- Helper files found in the *helpers/* directory +- Custom config files found in the *config/* directory +- Language files found in the *system/language/* directory +- Models found in the *models/* folder -To autoload resources, open the application/config/autoload.php file and -add the item you want loaded to the autoload array. You'll find -instructions in that file corresponding to each type of item. +To autoload resources, open the *application/config/autoload.php* +file and add the item you want loaded to the autoload array. You'll +find instructions in that file corresponding to each type of item. .. note:: Do not include the file extension (.php) when adding items to - the autoload array. + the autoload array. \ No newline at end of file diff --git a/user_guide_src/source/general/caching.rst b/user_guide_src/source/general/caching.rst index bf6ed50f6..c40f652ac 100644 --- a/user_guide_src/source/general/caching.rst +++ b/user_guide_src/source/general/caching.rst @@ -23,36 +23,38 @@ will be retrieved and sent to the requesting user's browser. If it has expired, it will be deleted and refreshed before being sent to the browser. -Note: The Benchmark tag is not cached so you can still view your page -load speed when caching is enabled. +.. note: The Benchmark tag is not cached so you can still view your page + load speed when caching is enabled. Enabling Caching ================ To enable caching, put the following tag in any of your controller -functions:: +methods:: - $this->output->cache(n); + $this->output->cache($n); -Where n is the number of **minutes** you wish the page to remain cached -between refreshes. +Where ``$n`` is the number of **minutes** you wish the page to remain +cached between refreshes. -The above tag can go anywhere within a function. It is not affected by +The above tag can go anywhere within a method. It is not affected by the order that it appears, so place it wherever it seems most logical to you. Once the tag is in place, your pages will begin being cached. .. important:: Because of the way CodeIgniter stores content for output, - caching will only work if you are generating display for your controller - with a :doc:`view <./views>`. + caching will only work if you are generating display for your + controller with a :doc:`view <./views>`. .. note:: Before the cache files can be written you must set the file - permissions on your application/cache folder such that it is writable. + permissions on your *application/cache/* directory such that + it is writable. Deleting Caches =============== If you no longer wish to cache a file you can remove the caching tag and -it will no longer be refreshed when it expires. Note: Removing the tag -will not delete the cache immediately. It will have to expire normally. -If you need to remove it earlier you will need to manually delete it -from your cache folder. +it will no longer be refreshed when it expires. + +.. note:: Removing the tag will not delete the cache immediately. It will + have to expire normally. If you need to remove it earlier you + will need to manually delete it from your cache directory. \ No newline at end of file diff --git a/user_guide_src/source/general/cli.rst b/user_guide_src/source/general/cli.rst index 649d5d548..998d2a907 100644 --- a/user_guide_src/source/general/cli.rst +++ b/user_guide_src/source/general/cli.rst @@ -21,7 +21,7 @@ Why run via the command-line? There are many reasons for running CodeIgniter from the command-line, but they are not always obvious. -- Run your cron-jobs without needing to use wget or curl +- Run your cron-jobs without needing to use *wget* or *curl* - Make your cron-jobs inaccessible from being loaded in the URL by checking for ``$this->input->is_cli_request()`` - Make interactive "tasks" that can do things like set permissions, @@ -44,9 +44,8 @@ in it:: echo "Hello {$to}!".PHP_EOL; } } - ?> -Then save the file to your application/controllers/ folder. +Then save the file to your *application/controllers/* folder. Now normally you would visit the your site using a URL similar to this:: @@ -60,19 +59,20 @@ in Windows and navigate to our CodeIgniter project. $ cd /path/to/project; $ php index.php tools message -If you did it right, you should see Hello World!. +If you did it right, you should see *Hello World!* printed. .. code-block:: bash $ php index.php tools message "John Smith" Here we are passing it a argument in the same way that URL parameters -work. "John Smith" is passed as a argument and output is: Hello John -Smith!. +work. "John Smith" is passed as a argument and output is:: + + Hello John Smith! That's it! ========== That, in a nutshell, is all there is to know about controllers on the command line. Remember that this is just a normal controller, so routing -and _remap works fine. +and ``_remap()`` works fine. \ No newline at end of file diff --git a/user_guide_src/source/general/controllers.rst b/user_guide_src/source/general/controllers.rst index 150d2269c..729b08417 100644 --- a/user_guide_src/source/general/controllers.rst +++ b/user_guide_src/source/general/controllers.rst @@ -38,33 +38,32 @@ in it:: echo 'Hello World!'; } } - ?> -Then save the file to your application/controllers/ folder. +Then save the file to your *application/controllers/* directory. Now visit the your site using a URL similar to this:: example.com/index.php/blog/ -If you did it right, you should see Hello World!. +If you did it right, you should see: -Note: Class names must start with an uppercase letter. In other words, -this is valid:: + Hello World! + +.. important:: Class names must start with an uppercase letter. + +This is valid:: - This is **not** valid:: Also, always make sure your controller extends the parent controller class so that it can inherit all its methods. @@ -96,7 +95,6 @@ Let's try it. Add a new method to your controller:: echo 'Look at this!'; } } - ?> Now load the following URL to see the comment method:: @@ -125,7 +123,6 @@ Your method will be passed URI segments 3 and 4 ("sandals" and "123"):: echo $id; } } - ?> .. important:: If you are using the :doc:`URI Routing ` feature, the segments passed to your method will be the re-routed @@ -139,7 +136,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 @@ -167,7 +164,7 @@ be passed as a parameter to the ``_remap()`` method:: public function _remap($method) { - if ($method == 'some_method') + if ($method === 'some_method') { $this->$method(); } @@ -182,7 +179,7 @@ optional second parameter. This array can be used in combination with PHP's `call_user_func_array() `_ to emulate CodeIgniter's default behavior. -:: +Example:: public function _remap($method, $params = array()) { @@ -205,10 +202,10 @@ post-process the finalized data in some way and send it to the browser yourself. CodeIgniter permits you to add a method named ``_output()`` to your controller that will receive the finalized output data. -.. important:: If your controller contains a method named _output(), it - will **always** be called by the output class instead of echoing - the finalized data directly. The first parameter of the method - will contain the finalized output. +.. important:: If your controller contains a method named ``_output()``, + it will **always** be called by the output class instead of + echoing the finalized data directly. The first parameter of the + method will contain the finalized output. Here is an example:: @@ -217,24 +214,26 @@ Here is an example:: echo $output; } -.. note:: Please note that your _output() method will receive the data in its - finalized state. Benchmark and memory usage data will be rendered, cache - files written (if you have caching enabled), and headers will be sent - (if you use that :doc:`feature <../libraries/output>`) before it is - handed off to the _output() method. - To have your controller's output cached properly, its _output() method - can use:: +.. note:: Please note that your ``_output()`` method will receive the + data in its finalized state. Benchmark and memory usage data + will be rendered, cache files written (if you have caching + enabled), and headers will be sent (if you use that + :doc:`feature <../libraries/output>`) before it is handed off + to the ``_output()`` method. + To have your controller's output cached properly, its + ``_output()`` method can use:: if ($this->output->cache_expiration > 0) { - $this->output->_write_cache($output); + $this->output->_write_cache($output); } - If you are using this feature the page execution timer and memory usage - stats might not be perfectly accurate since they will not take into - acccount any further processing you do. For an alternate way to control - output *before* any of the final processing is done, please see the - available methods in the :doc:`Output Class <../libraries/output>`. + If you are using this feature the page execution timer and + memory usage stats might not be perfectly accurate since they + will not take into account any further processing you do. + For an alternate way to control output *before* any of the + final processing is done, please see the available methods + in the :doc:`Output Library <../libraries/output>`. Private methods =============== @@ -257,15 +256,15 @@ Trying to access it via the URL, like this, will not work:: them from being called. This is a legacy feature that is left for backwards-compatibility. -Organizing Your Controllers into Sub-folders -============================================ +Organizing Your Controllers into Sub-directories +================================================ If you are building a large application you might find it convenient to -organize your controllers into sub-folders. CodeIgniter permits you to -do this. +organize your controllers into sub-directories. CodeIgniter permits you +to do this. -Simply create folders within your application/controllers directory and -place your controller classes within them. +Simply create folders within your *application/controllers/* directory +and place your controller classes within them. .. note:: When using this feature the first segment of your URI must specify the folder. For example, lets say you have a controller located @@ -277,9 +276,9 @@ place your controller classes within them. example.com/index.php/products/shoes/show/123 -Each of your sub-folders may contain a default controller which will be +Each of your sub-directories may contain a default controller which will be called if the URL contains only the sub-folder. Simply name your default -controller as specified in your application/config/routes.php file +controller as specified in your *application/config/routes.php* file. CodeIgniter also permits you to remap your URIs using its :doc:`URI Routing ` feature. @@ -296,7 +295,7 @@ The reason this line is necessary is because your local constructor will be overriding the one in the parent controller class so we need to manually call it. -:: +Example:: Constructors are useful if you need to set some default values, or run a default process when your class is instantiated. Constructors can't @@ -323,9 +321,9 @@ override them. See :doc:`Reserved Names ` for a full list. .. important:: You should also never have a method named identically - to its class name. If you do, and there is no __construct() - method in the same class, then your e.g. Index::index() method - will be executed as a class constructor! This is a PHP4 + to its class name. If you do, and there is no ``__construct()`` + method in the same class, then your e.g. ``Index::index()`` + method will be executed as a class constructor! This is a PHP4 backwards-compatibility feature. That's it! diff --git a/user_guide_src/source/general/core_classes.rst b/user_guide_src/source/general/core_classes.rst index 4aa6693f7..ce57aeef0 100644 --- a/user_guide_src/source/general/core_classes.rst +++ b/user_guide_src/source/general/core_classes.rst @@ -39,9 +39,9 @@ Replacing Core Classes ====================== To use one of your own system classes instead of a default one simply -place your version inside your local application/core directory:: +place your version inside your local *application/core/* directory:: - application/core/some-class.php + application/core/some_class.php If this directory does not exist you can create it. @@ -59,7 +59,7 @@ Extending Core Class ==================== If all you need to do is add some functionality to an existing library - -perhaps add a function or two - then it's overkill to replace the entire +perhaps add a method or two - then it's overkill to replace the entire library with your version. In this case it's better to simply extend the class. Extending a class is nearly identical to replacing a class with a couple exceptions: @@ -75,19 +75,19 @@ application/core/MY_Input.php, and declare your class with:: } -Note: If you need to use a constructor in your class make sure you +.. note:: If you need to use a constructor in your class make sure you extend the parent constructor:: class MY_Input extends CI_Input { - function __construct() - { - parent::__construct(); - } + public function __construct() + { + parent::__construct(); + } } **Tip:** Any functions in your class that are named identically to the -functions in the parent class will be used instead of the native ones +methods in the parent class will be used instead of the native ones (this is known as "method overriding"). This allows you to substantially alter the CodeIgniter core. @@ -98,24 +98,24 @@ your new class in your application controller's constructors. class Welcome extends MY_Controller { - function __construct() - { - parent::__construct(); - } + public function __construct() + { + parent::__construct(); + } - function index() - { - $this->load->view('welcome_message'); - } + public function index() + { + $this->load->view('welcome_message'); + } } Setting Your Own Prefix ----------------------- To set your own sub-class prefix, open your -application/config/config.php file and look for this item:: +*application/config/config.php* file and look for this item:: $config['subclass_prefix'] = 'MY_'; -Please note that all native CodeIgniter libraries are prefixed with CI\_ -so DO NOT use that as your prefix. +Please note that all native CodeIgniter libraries are prefixed +with CI\_ so DO NOT use that as your prefix. \ No newline at end of file diff --git a/user_guide_src/source/general/creating_drivers.rst b/user_guide_src/source/general/creating_drivers.rst index 0e22e4f14..cf4ea5d7f 100644 --- a/user_guide_src/source/general/creating_drivers.rst +++ b/user_guide_src/source/general/creating_drivers.rst @@ -16,5 +16,6 @@ Sample driver directory and file structure layout: - Driver_name_subclass_2.php - Driver_name_subclass_3.php -**NOTE:** In order to maintain compatibility on case-sensitive file -systems, the Driver_name directory must be ucfirst() +.. note:: In order to maintain compatibility on case-sensitive + file systems, the Driver_name directory must be + named in the format returned by ``ucfirst()``. \ No newline at end of file diff --git a/user_guide_src/source/general/creating_libraries.rst b/user_guide_src/source/general/creating_libraries.rst index 673fbd4bb..8bafd4532 100644 --- a/user_guide_src/source/general/creating_libraries.rst +++ b/user_guide_src/source/general/creating_libraries.rst @@ -12,7 +12,7 @@ your local resources and the global framework resources. As an added bonus, CodeIgniter permits your libraries to extend native classes if you simply need to add some functionality to an existing library. Or you can even replace native libraries just by placing -identically named versions in your application/libraries folder. +identically named versions in your *application/libraries* directory. In summary: @@ -28,8 +28,8 @@ The page below explains these three concepts in detail. Storage ======= -Your library classes should be placed within your application/libraries -folder, as this is where CodeIgniter will look for them when they are +Your library classes should be placed within your *application/libraries* +directory, as this is where CodeIgniter will look for them when they are initialized. Naming Conventions @@ -49,9 +49,9 @@ Someclass purely as an example):: class Someclass { - public function some_function() - { - } + public function some_method() + { + } } /* End of file Someclass.php */ @@ -59,7 +59,7 @@ Someclass purely as an example):: Using Your Class ================ -From within any of your :doc:`Controller ` functions you +From within any of your :doc:`Controller ` methods you can initialize your class using the standard:: $this->load->library('someclass'); @@ -70,12 +70,12 @@ doesn't care. Once loaded you can access your class using the lower case version:: - $this->someclass->some_function();  // Object instances will always be lower case + $this->someclass->some_method();  // Object instances will always be lower case Passing Parameters When Initializing Your Class =============================================== -In the library loading function you can dynamically pass data as an +In the library loading method you can dynamically pass data as an array via the second parameter and it will be passed to your class constructor:: @@ -86,21 +86,19 @@ constructor:: If you use this feature you must set up your class constructor to expect data:: - - You can also pass parameters stored in a config file. Simply create a config file named identically to the class file name and store it in -your application/config/ folder. Note that if you dynamically pass +your *application/config/* directory. Note that if you dynamically pass parameters as described above, the config file option will not be available. @@ -108,18 +106,18 @@ Utilizing CodeIgniter Resources within Your Library =================================================== To access CodeIgniter's native resources within your library use the -get_instance() function. This function returns the CodeIgniter super +``get_instance()`` method. This method returns the CodeIgniter super object. -Normally from within your controller functions you will call any of the -available CodeIgniter functions using the $this construct:: +Normally from within your controller methods you will call any of the +available CodeIgniter methods using the ``$this`` construct:: $this->load->helper('url'); $this->load->library('session'); $this->config->item('base_url'); // etc. -$this, however, only works directly within your controllers, your +``$this``, however, only works directly within your controllers, your models, or your views. If you would like to use CodeIgniter's classes from within your own custom classes you can do so as follows: @@ -128,7 +126,7 @@ First, assign the CodeIgniter object to a variable:: $CI =& get_instance(); Once you've assigned the object to a variable, you'll use that variable -*instead* of $this:: +*instead* of ``$this``:: $CI =& get_instance(); @@ -137,7 +135,7 @@ Once you've assigned the object to a variable, you'll use that variable $CI->config->item('base_url'); // etc. -.. note:: You'll notice that the above get_instance() function is being +.. note:: You'll notice that the above ``get_instance()`` function is being passed by reference:: $CI =& get_instance(); @@ -145,6 +143,36 @@ Once you've assigned the object to a variable, you'll use that variable This is very important. Assigning by reference allows you to use the original CodeIgniter object rather than creating a copy of it. +However, since a library is a class, it would be better if you +take full advantage of the OOP principles. So, in order to +be able to use the CodeIgniter super-object in all of the class +methods, you're encouraged to assign it to a property instead:: + +class Example_library { + + protected $CI; + + // We'll use a constructor, as you can't directly call a function + // from a property definition. + public function __construct() + { + // Assign the CodeIgniter super-object + $this->CI =& get_instance(); + } + + public function foo() + { + $this->CI->load->helper('url'); + redirect(); + } + + public function bar() + { + echo $this->CI->config_item('base_url'); + } + +} + Replacing Native Libraries with Your Versions ============================================= @@ -152,8 +180,8 @@ Simply by naming your class files identically to a native library will cause CodeIgniter to use it instead of the native one. To use this feature you must name the file and the class declaration exactly the same as the native library. For example, to replace the native Email -library you'll create a file named application/libraries/Email.php, and -declare your class with:: +library you'll create a file named *application/libraries/Email.php*, +and declare your class with:: class CI_Email { @@ -161,7 +189,7 @@ declare your class with:: Note that most native classes are prefixed with CI\_. -To load your library you'll see the standard loading function:: +To load your library you'll see the standard loading method:: $this->load->library('email'); @@ -172,7 +200,7 @@ Extending Native Libraries ========================== If all you need to do is add some functionality to an existing library - -perhaps add a function or two - then it's overkill to replace the entire +perhaps add a method or two - then it's overkill to replace the entire library with your version. In this case it's better to simply extend the class. Extending a class is nearly identical to replacing a class with a couple exceptions: @@ -182,7 +210,7 @@ couple exceptions: item is configurable. See below.). For example, to extend the native Email class you'll create a file named -application/libraries/MY_Email.php, and declare your class with:: +*application/libraries/MY_Email.php*, and declare your class with:: class MY_Email extends CI_Email { @@ -200,8 +228,7 @@ extend the parent constructor:: } -.. note:: - Not all of the libraries have the same (or any) parameters +.. note:: Not all of the libraries have the same (or any) parameters in their constructor. Take a look at the library that you're extending first to see how it should be implemented. @@ -218,15 +245,15 @@ Once loaded you will use the class variable as you normally would for the class you are extending. In the case of the email class all calls will use:: - $this->email->some_function(); + $this->email->some_method(); Setting Your Own Prefix ----------------------- To set your own sub-class prefix, open your -application/config/config.php file and look for this item:: +*application/config/config.php* file and look for this item:: $config['subclass_prefix'] = 'MY_'; Please note that all native CodeIgniter libraries are prefixed with CI\_ -so DO NOT use that as your prefix. +so DO NOT use that as your prefix. \ No newline at end of file diff --git a/user_guide_src/source/general/credits.rst b/user_guide_src/source/general/credits.rst index 2c7459894..03ee83dd6 100644 --- a/user_guide_src/source/general/credits.rst +++ b/user_guide_src/source/general/credits.rst @@ -16,4 +16,4 @@ of the Reactor Team. A hat tip goes to Ruby on Rails for inspiring us to create a PHP framework, and for bringing frameworks into the general consciousness of -the web community. +the web community. \ No newline at end of file diff --git a/user_guide_src/source/general/drivers.rst b/user_guide_src/source/general/drivers.rst index e2ded62e2..b64b0e75e 100644 --- a/user_guide_src/source/general/drivers.rst +++ b/user_guide_src/source/general/drivers.rst @@ -8,18 +8,18 @@ parent class, but not their siblings. Drivers provide an elegant syntax in your :doc:`controllers ` for libraries that benefit from or require being broken down into discrete classes. -Drivers are found in the system/libraries folder, in their own folder -which is identically named to the parent library class. Also inside that -folder is a subfolder named drivers, which contains all of the possible -child class files. +Drivers are found in the *system/libraries/* directory, in their own +sub-directory which is identically named to the parent library class. +Also inside that directory is a subdirectory named drivers, which +contains all of the possible child class files. To use a driver you will initialize it within a controller using the -following initialization function:: +following initialization method:: - $this->load->driver('class name'); + $this->load->driver('class_name'); Where class name is the name of the driver class you want to invoke. For -example, to load a driver named "Some Parent" you would do this:: +example, to load a driver named "Some_parent" you would do this:: $this->load->driver('some_parent'); @@ -37,4 +37,4 @@ Creating Your Own Drivers ========================= Please read the section of the user guide that discusses how to :doc:`create -your own drivers `. +your own drivers `. \ No newline at end of file diff --git a/user_guide_src/source/general/environments.rst b/user_guide_src/source/general/environments.rst index fa1b096e2..d74ebb8d5 100644 --- a/user_guide_src/source/general/environments.rst +++ b/user_guide_src/source/general/environments.rst @@ -11,8 +11,8 @@ when "live". The ENVIRONMENT Constant ======================== -By default, CodeIgniter comes with the environment constant set to use -the value provided in ``$_SERVER['CI_ENV']``, otherwise defaults to +By default, CodeIgniter comes with the environment constant set to use +the value provided in ``$_SERVER['CI_ENV']``, otherwise defaults to 'development'. At the top of index.php, you will see:: define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development'); @@ -49,4 +49,4 @@ Optionally, you can have CodeIgniter load environment-specific configuration files. This may be useful for managing things like differing API keys across multiple environments. This is described in more detail in the environment section of the `Config -Class <../libraries/config.html#environments>`_ documentation. +Class <../libraries/config.html#environments>`_ documentation. \ No newline at end of file diff --git a/user_guide_src/source/general/errors.rst b/user_guide_src/source/general/errors.rst index 91b59140f..8c941aadb 100644 --- a/user_guide_src/source/general/errors.rst +++ b/user_guide_src/source/general/errors.rst @@ -20,47 +20,69 @@ without having to worry about class/function scoping. The following functions let you generate errors: -show_error('message' [, int $status_code= 500 ] ) -=================================================== +show_error() +============ + +.. php:function:: show_error($message, $status_code, $heading = 'An Error Was Encountered') + + :param mixed $message: Error message + :param int $status_code: HTTP Response status code + :param string $heading: Error page heading + :returns: void This function will display the error message supplied to it using the -following error template: +following error template:: + + application/errors/error_general.php + +The optional parameter ``$status_code`` determines what HTTP status +code should be sent with the error. -application/errors/error_general.php +show_404() +========== -The optional parameter $status_code determines what HTTP status code -should be sent with the error. +.. php:function:: show_404($page = '', $log_error = TRUE) -show_404('page' [, 'log_error']) -================================== + :param string $page: URI string + :param bool $log_error: Whether to log the error + :returns: void This function will display the 404 error message supplied to it using -the following error template: +the following error template:: -application/errors/error_404.php + application/errors/error_404.php The function expects the string passed to it to be the file path to the page that isn't found. Note that CodeIgniter automatically shows 404 messages if controllers are not found. -CodeIgniter automatically logs any show_404() calls. Setting the +CodeIgniter automatically logs any ``show_404()`` calls. Setting the optional second parameter to FALSE will skip logging. -log_message('level', 'message') -================================ +log_message() +============= + +.. php:function:: log_message($level = 'error', $message, $php_error = FALSE) + + :param string $level: Log level + :param string $message: Message to log + :param bool $php_error: Whether we're loggin a native PHP error message + :returns: void This function lets you write messages to your log files. You must supply one of three "levels" in the first parameter, indicating what type of message it is (debug, error, info), with the message itself in the -second parameter. Example:: +second parameter. + +Example:: - if ($some_var == "") + if ($some_var == '') { - log_message('error', 'Some variable did not contain a value.'); + log_message('error', 'Some variable did not contain a value.'); } else { - log_message('debug', 'Some variable was correctly set'); + log_message('debug', 'Some variable was correctly set'); } log_message('info', 'The purpose of some variable is to provide some value.'); @@ -77,8 +99,8 @@ There are three message types: natively generate any info messages but you may want to in your application. -.. note:: In order for the log file to actually be written, the "logs" - folder must be writable. In addition, you must set the "threshold" for - logging in application/config/config.php. You might, for example, only - want error messages to be logged, and not the other two types. If you - set it to zero logging will be disabled. +.. note:: In order for the log file to actually be written, the *logs* + directory must be writable. In addition, you must set the "threshold" + for logging in *application/config/config.php*. You might, for example, + only want error messages to be logged, and not the other two types. + If you set it to zero logging will be disabled. \ No newline at end of file diff --git a/user_guide_src/source/general/helpers.rst b/user_guide_src/source/general/helpers.rst index 3a98311a6..d171aa8ed 100644 --- a/user_guide_src/source/general/helpers.rst +++ b/user_guide_src/source/general/helpers.rst @@ -23,12 +23,12 @@ Helpers are typically stored in your **system/helpers**, or **application/helpers directory**. CodeIgniter will look first in your **application/helpers directory**. If the directory does not exist or the specified helper is not located there CI will instead look in your -global system/helpers folder. +global *system/helpers/* directory. Loading a Helper ================ -Loading a helper file is quite simple using the following function:: +Loading a helper file is quite simple using the following method:: $this->load->helper('name'); @@ -40,15 +40,15 @@ For example, to load the **URL Helper** file, which is named $this->load->helper('url'); -A helper can be loaded anywhere within your controller functions (or +A helper can be loaded anywhere within your controller methods (or even within your View files, although that's not a good practice), as long as you load it before you use it. You can load your helpers in your controller constructor so that they become available automatically in any function, or you can load a helper in a specific function that needs it. -Note: The Helper loading function above does not return a value, so -don't try to assign it to a variable. Just use it as shown. +.. note:: The Helper loading method above does not return a value, so + don't try to assign it to a variable. Just use it as shown. Loading Multiple Helpers ======================== @@ -56,14 +56,16 @@ Loading Multiple Helpers If you need to load more than one helper you can specify them in an array, like this:: - $this->load->helper( array('helper1', 'helper2', 'helper3') ); + $this->load->helper( + array('helper1', 'helper2', 'helper3') + ); Auto-loading Helpers ==================== If you find that you need a particular helper globally throughout your application, you can tell CodeIgniter to auto-load it during system -initialization. This is done by opening the **application/config/autoload.php** +initialization. This is done by opening the **application/config/autoload.php** file and adding the helper to the autoload array. Using a Helper @@ -72,13 +74,13 @@ Using a Helper Once you've loaded the Helper File containing the function you intend to use, you'll call it the way you would a standard PHP function. -For example, to create a link using the anchor() function in one of your -view files you would do this:: +For example, to create a link using the ``anchor()`` function in one of +your view files you would do this:: Where "Click Here" is the name of the link, and "blog/comments" is the -URI to the controller/function you wish to link to. +URI to the controller/method you wish to link to. "Extending" Helpers =================== @@ -91,11 +93,11 @@ If all you need to do is add some functionality to an existing helper - perhaps add a function or two, or change how a particular helper function operates - then it's overkill to replace the entire helper with your version. In this case it's better to simply "extend" the Helper. -The term "extend" is used loosely since Helper functions are procedural -and discrete and cannot be extended in the traditional programmatic -sense. Under the hood, this gives you the ability to add to the -functions a Helper provides, or to modify how the native Helper -functions operate. + +.. note:: The term "extend" is used loosely since Helper functions are + procedural and discrete and cannot be extended in the traditional + programmatic sense. Under the hood, this gives you the ability to + add to or or to replace the functions a Helper provides. For example, to extend the native **Array Helper** you'll create a file named **application/helpers/MY_array_helper.php**, and add or override @@ -104,31 +106,31 @@ functions:: // any_in_array() is not in the Array Helper, so it defines a new function function any_in_array($needle, $haystack) { - $needle = (is_array($needle)) ? $needle : array($needle); - - foreach ($needle as $item) - { - if (in_array($item, $haystack)) - { - return TRUE; - } + $needle = is_array($needle) ? $needle : array($needle); + + foreach ($needle as $item) + { + if (in_array($item, $haystack)) + { + return TRUE; + } } - return FALSE; + return FALSE; } // random_element() is included in Array Helper, so it overrides the native function function random_element($array) { - shuffle($array); - return array_pop($array); + shuffle($array); + return array_pop($array); } Setting Your Own Prefix ----------------------- The filename prefix for "extending" Helpers is the same used to extend -libraries and Core classes. To set your own prefix, open your +libraries and core classes. To set your own prefix, open your **application/config/config.php** file and look for this item:: $config['subclass_prefix'] = 'MY_'; @@ -140,4 +142,4 @@ Now What? ========= In the Table of Contents you'll find a list of all the available Helper -Files. Browse each one to see what they do. +Files. Browse each one to see what they do. \ No newline at end of file diff --git a/user_guide_src/source/general/hooks.rst b/user_guide_src/source/general/hooks.rst index 65696f6c7..fc5da5b80 100644 --- a/user_guide_src/source/general/hooks.rst +++ b/user_guide_src/source/general/hooks.rst @@ -16,25 +16,26 @@ Enabling Hooks ============== The hooks feature can be globally enabled/disabled by setting the -following item in the application/config/config.php file:: +following item in the **application/config/config.php** file:: $config['enable_hooks'] = TRUE; Defining a Hook =============== -Hooks are defined in application/config/hooks.php file. Each hook is -specified as an array with this prototype:: +Hooks are defined in **application/config/hooks.php** file. +Each hook is specified as an array with this prototype:: $hook['pre_controller'] = array( - 'class' => 'MyClass', - 'function' => 'Myfunction', - 'filename' => 'Myclass.php', - 'filepath' => 'hooks', - 'params' => array('beer', 'wine', 'snacks') - ); + 'class' => 'MyClass', + 'function' => 'Myfunction', + 'filename' => 'Myclass.php', + 'filepath' => 'hooks', + 'params' => array('beer', 'wine', 'snacks') + ); **Notes:** + The array index correlates to the name of the particular hook point you want to use. In the above example the hook point is pre_controller. A list of hook points is found below. The following items should be @@ -42,14 +43,15 @@ defined in your associative hook array: - **class** The name of the class you wish to invoke. If you prefer to use a procedural function instead of a class, leave this item blank. -- **function** The function name you wish to call. +- **function** The function (or method) name you wish to call. - **filename** The file name containing your class/function. -- **filepath** The name of the directory containing your script. Note: - Your script must be located in a directory INSIDE your application - folder, so the file path is relative to that folder. For example, if - your script is located in application/hooks, you will simply use - hooks as your filepath. If your script is located in - application/hooks/utilities you will use hooks/utilities as your +- **filepath** The name of the directory containing your script. + Note: + Your script must be located in a directory INSIDE your *application/* + directory, so the file path is relative to that directory. For example, + if your script is located in *application/hooks/*, you will simply use + 'hooks' as your filepath. If your script is located in + *application/hooks/utilities/* you will use 'hooks/utilities' as your filepath. No trailing slash. - **params** Any parameters you wish to pass to your script. This item is optional. @@ -61,20 +63,20 @@ If want to use the same hook point with more then one script, simply make your array declaration multi-dimensional, like this:: $hook['pre_controller'][] = array( - 'class' => 'MyClass', - 'function' => 'Myfunction', - 'filename' => 'Myclass.php', - 'filepath' => 'hooks', - 'params' => array('beer', 'wine', 'snacks') - ); + 'class' => 'MyClass', + 'function' => 'MyMethod', + 'filename' => 'Myclass.php', + 'filepath' => 'hooks', + 'params' => array('beer', 'wine', 'snacks') + ); $hook['pre_controller'][] = array( - 'class' => 'MyOtherClass', - 'function' => 'MyOtherfunction', - 'filename' => 'Myotherclass.php', - 'filepath' => 'hooks', - 'params' => array('red', 'yellow', 'blue') - ); + 'class' => 'MyOtherClass', + 'function' => 'MyOtherMethod', + 'filename' => 'Myotherclass.php', + 'filepath' => 'hooks', + 'params' => array('red', 'yellow', 'blue') + ); Notice the brackets after each array index:: @@ -101,18 +103,17 @@ The following is a list of available hook points. - **post_controller** Called immediately after your controller is fully executed. - **display_override** - Overrides the _display() function, used to send the finalized page + Overrides the ``_display()`` method, used to send the finalized page to the web browser at the end of system execution. This permits you to use your own display methodology. Note that you will need to - reference the CI superobject with $this->CI =& get_instance() and + reference the CI superobject with ``$this->CI =& get_instance()`` and then the finalized data will be available by calling - $this->CI->output->get_output() + ``$this->CI->output->get_output()``. - **cache_override** - Enables you to call your own function instead of the - _display_cache() function in the output class. This permits you to - use your own cache display mechanism. + Enables you to call your own method instead of the ``_display_cache()`` + method in the :doc:`Output Library <../libraries/output>`. This permits + you to use your own cache display mechanism. - **post_system** Called after the final rendered page is sent to the browser, at the end of system execution after the finalized data is sent to the - browser. - + browser. \ No newline at end of file diff --git a/user_guide_src/source/general/index.rst b/user_guide_src/source/general/index.rst index 2162b8140..2bc684a1d 100644 --- a/user_guide_src/source/general/index.rst +++ b/user_guide_src/source/general/index.rst @@ -29,4 +29,4 @@ General Topics environments alternative_php security - PHP Style Guide + PHP Style Guide \ No newline at end of file diff --git a/user_guide_src/source/general/libraries.rst b/user_guide_src/source/general/libraries.rst index 954a5b8f8..6e1c8b6dd 100644 --- a/user_guide_src/source/general/libraries.rst +++ b/user_guide_src/source/general/libraries.rst @@ -2,30 +2,31 @@ Using CodeIgniter Libraries ########################### -All of the available libraries are located in your system/libraries -folder. In most cases, to use one of these classes involves initializing +All of the available libraries are located in your *system/libraries/* +directory. In most cases, to use one of these classes involves initializing it within a :doc:`controller ` using the following -initialization function:: +initialization method:: - $this->load->library('class name'); + $this->load->library('class_name'); -Where class name is the name of the class you want to invoke. For -example, to load the form validation class you would do this:: +Where 'class_name' is the name of the class you want to invoke. For +example, to load the :doc:`Form Validation Library +<../libraries/form_validation>` you would do this:: - $this->load->library('form_validation'); + $this->load->library('form_validation'); Once initialized you can use it as indicated in the user guide page corresponding to that class. Additionally, multiple libraries can be loaded at the same time by -passing an array of libraries to the load function. +passing an array of libraries to the load method. -:: +Example:: $this->load->library(array('email', 'table')); Creating Your Own Libraries =========================== -Please read the section of the user guide that discusses how to :doc:`create -your own libraries ` +Please read the section of the user guide that discusses how to +:doc:`create your own libraries `. diff --git a/user_guide_src/source/general/managing_apps.rst b/user_guide_src/source/general/managing_apps.rst index 996481354..afb1aba2e 100644 --- a/user_guide_src/source/general/managing_apps.rst +++ b/user_guide_src/source/general/managing_apps.rst @@ -3,41 +3,39 @@ Managing your Applications ########################## By default it is assumed that you only intend to use CodeIgniter to -manage one application, which you will build in your application/ +manage one application, which you will build in your *application/* directory. It is possible, however, to have multiple sets of applications that share a single CodeIgniter installation, or even to -rename or relocate your application folder. +rename or relocate your application directory. -Renaming the Application Folder -=============================== - -If you would like to rename your application folder you may do so as -long as you open your main index.php file and set its name using the -$application_folder variable:: +Renaming the Application Directory +================================== - $application_folder = "application"; +If you would like to rename your application directory you may do so +as long as you open your main index.php file and set its name using +the ``$application_folder`` variable:: -Relocating your Application Folder -================================== + $application_folder = 'application'; -It is possible to move your application folder to a different location -on your server than your system folder. To do so open your main -index.php and set a *full server path* in the $application_folder -variable. +Relocating your Application Directory +===================================== -:: +It is possible to move your application directory to a different +location on your server than your system directory. To do so open +your main index.php and set a *full server path* in the +``$application_folder`` variable:: - $application_folder = "/Path/to/your/application"; + $application_folder = '/path/to/your/application'; Running Multiple Applications with one CodeIgniter Installation =============================================================== If you would like to share a common CodeIgniter installation to manage several different applications simply put all of the directories located -inside your application folder into their own sub-folder. +inside your application directory into their own sub-directory. -For example, let's say you want to create two applications, "foo" and -"bar". You could structure your application folders like this:: +For example, let's say you want to create two applications, named "foo" +and "bar". You could structure your application directories like this:: applications/foo/ applications/foo/config/ @@ -55,11 +53,11 @@ For example, let's say you want to create two applications, "foo" and applications/bar/views/ To select a particular application for use requires that you open your -main index.php file and set the $application_folder variable. For +main index.php file and set the ``$application_folder`` variable. For example, to select the "foo" application for use you would do this:: - $application_folder = "applications/foo"; + $application_folder = 'applications/foo'; .. note:: Each of your applications will need its own index.php file which calls the desired application. The index.php file can be named - anything you want. + anything you want. \ 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 4e52a9648..a028a9569 100644 --- a/user_guide_src/source/general/models.rst +++ b/user_guide_src/source/general/models.rst @@ -18,55 +18,56 @@ model class might look like:: class Blog_model extends CI_Model { - public $title = ''; - public $content = ''; - public $date = ''; - - function __construct() - { - // Call the Model constructor - parent::__construct(); - } - - function get_last_ten_entries() - { - $query = $this->db->get('entries', 10); - return $query->result(); - } - - function insert_entry() - { - $this->title = $_POST['title']; // please read the below note - $this->content = $_POST['content']; - $this->date = time(); - - $this->db->insert('entries', $this); - } - - function update_entry() - { - $this->title = $_POST['title']; - $this->content = $_POST['content']; - $this->date = time(); - - $this->db->update('entries', $this, array('id' => $_POST['id'])); - } + public $title; + public $content; + public $date; + + public function __construct() + { + // Call the CI_Model constructor + parent::__construct(); + } + + public function get_last_ten_entries() + { + $query = $this->db->get('entries', 10); + return $query->result(); + } + + public function insert_entry() + { + $this->title = $_POST['title']; // please read the below note + $this->content = $_POST['content']; + $this->date = time(); + + $this->db->insert('entries', $this); + } + + public function update_entry() + { + $this->title = $_POST['title']; + $this->content = $_POST['content']; + $this->date = time(); + + $this->db->update('entries', $this, array('id' => $_POST['id'])); + } } -.. note:: The functions in the above example use the :doc:`Active - Record <../database/query_builder>` database functions. +.. note:: The methods in the above example use the :doc:`Query Builder + <../database/query_builder>` database methods. -.. note:: For the sake of simplicity in this example we're using $_POST +.. note:: For the sake of simplicity in this example we're using ``$_POST`` directly. This is generally bad practice, and a more common approach - would be to use the :doc:`Input Class <../libraries/input>` - $this->input->post('title') + would be to use the :doc:`Input Library <../libraries/input>` + ``$this->input->post('title')``. Anatomy of a Model ================== -Model classes are stored in your **application/models/ folder**. They can be -nested within sub-folders if you want this type of organization. +Model classes are stored in your **application/models/** directory. +They can be nested within sub-directories if you want this type of +organization. The basic prototype for a model class is this:: @@ -103,14 +104,14 @@ Loading a Model =============== Your models will typically be loaded and called from within your -:doc:`controller ` functions. To load a model you will use +:doc:`controller ` methods. To load a model you will use the following method:: $this->load->model('model_name'); -If your model is located in a sub-folder, include the relative path from -your models folder. For example, if you have a model located at -application/models/blog/queries.php you'll load it using:: +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:: $this->load->model('blog/queries'); @@ -141,7 +142,6 @@ view:: $this->load->view('blog', $data); } - } @@ -163,10 +163,9 @@ database. The following options for connecting are available to you: - You can connect using the standard database methods :doc:`described here <../database/connecting>`, either from within your Controller class or your Model class. -- You can tell the model loading function to auto-connect by passing - TRUE (boolean) via the third parameter, and connectivity settings, as - defined in your database config file will be used: - :: +- You can tell the model loading method to auto-connect by passing + TRUE (boolean) via the third parameter, and connectivity settings, + as defined in your database config file will be used:: $this->load->model('model_name', '', TRUE); diff --git a/user_guide_src/source/general/profiling.rst b/user_guide_src/source/general/profiling.rst index 437635289..6dbd0be16 100644 --- a/user_guide_src/source/general/profiling.rst +++ b/user_guide_src/source/general/profiling.rst @@ -3,7 +3,7 @@ Profiling Your Application ########################## The Profiler Class will display benchmark results, queries you have run, -and $_POST data at the bottom of your pages. This information can be +and ``$_POST`` data at the bottom of your pages. This information can be useful during development in order to help with debugging and optimization. @@ -11,14 +11,14 @@ Initializing the Class ====================== .. important:: This class does NOT need to be initialized. It is loaded - automatically by the :doc:`Output Class <../libraries/output>` if - profiling is enabled as shown below. + automatically by the :doc:`Output Library <../libraries/output>` + if profiling is enabled as shown below. Enabling the Profiler ===================== -To enable the profiler place the following function anywhere within your -:doc:`Controller ` functions:: +To enable the profiler place the following line anywhere within your +:doc:`Controller ` methods:: $this->output->enable_profiler(TRUE); @@ -35,8 +35,8 @@ Setting Benchmark Points In order for the Profiler to compile and display your benchmark data you must name your mark points using specific syntax. -Please read the information on setting Benchmark points in :doc:`Benchmark -Class <../libraries/benchmark>` page. +Please read the information on setting Benchmark points in the +:doc:`Benchmark Library <../libraries/benchmark>` page. Enabling and Disabling Profiler Sections ======================================== @@ -44,21 +44,21 @@ Enabling and Disabling Profiler Sections Each section of Profiler data can be enabled or disabled by setting a corresponding config variable to TRUE or FALSE. This can be done one of two ways. First, you can set application wide defaults with the -application/config/profiler.php config file. +*application/config/profiler.php* config file. -:: +Example:: $config['config'] = FALSE; $config['queries'] = FALSE; In your controllers, you can override the defaults and config file -values by calling the set_profiler_sections() method of the :doc:`Output -class <../libraries/output>`:: +values by calling the ``set_profiler_sections()`` method of the +:doc:`Output Library <../libraries/output>`:: $sections = array( - 'config' => TRUE, - 'queries' => TRUE - ); + 'config' => TRUE, + 'queries' => TRUE + ); $this->output->set_profiler_sections($sections); diff --git a/user_guide_src/source/general/requirements.rst b/user_guide_src/source/general/requirements.rst index d9edfba6d..104923625 100644 --- a/user_guide_src/source/general/requirements.rst +++ b/user_guide_src/source/general/requirements.rst @@ -3,7 +3,13 @@ Server Requirements ################### - `PHP `_ version 5.2.4 or newer. -- A Database is required for most web application programming. Current - supported databases are MySQL (5.1+), MySQLi, Oracle, PostgreSQL, - MS SQL, SQLSRV (SQL Server 2005+), SQLite, SQLite3, CUBRID, Interbase, - ODBC and PDO. +- A Database is required for most web application programming. + Currently supported databases are: + - MySQL (5.1+) via the *mysql* (deprecated), *mysqli* and *pdo* drivers + - Oracle via the *oci8* and *pdo* drivers + - PostgreSQL via the *postgre* and *pdo* drivers + - MS SQL via the *mssql*, *sqlsrv* (version 2005 and above only) and *pdo* drivers + - SQLite via the *sqlite* (version 2), *sqlite3* (version 3) and *pdo* drivers + - CUBRID via the *cubrid* and *pdo* drivers + - Interbase/Firebird via the *ibase* and *pdo* drivers + - ODBC via the *odbc* and *pdo* drivers (you should know that ODBC is actually an abstraction layer) \ No newline at end of file diff --git a/user_guide_src/source/general/reserved_names.rst b/user_guide_src/source/general/reserved_names.rst index 3354375c5..d91292363 100644 --- a/user_guide_src/source/general/reserved_names.rst +++ b/user_guide_src/source/general/reserved_names.rst @@ -2,16 +2,17 @@ Reserved Names ############## -In order to help out, CodeIgniter uses a series of functions and names -in its operation. Because of this, some names cannot be used by a -developer. Following is a list of reserved names that cannot be used. +In order to help out, CodeIgniter uses a series of function, method, +class and variable names in its operation. Because of this, some names +cannot be used by a developer. Following is a list of reserved names +that cannot be used. Controller names ---------------- Since your controller classes will extend the main application -controller you must be careful not to name your functions identically to -the ones used by that class, otherwise your local functions will +controller you must be careful not to name your methods identically to +the ones used by that class, otherwise your local methods will override them. The following is a list of reserved names. Do not name your controller any of these: @@ -24,22 +25,25 @@ your controller any of these: Functions --------- -- is_really_writable() -- load_class() -- get_config() -- config_item() -- show_error() -- show_404() -- log_message() -- _exception_handler() -- get_instance() +- :php:func:`is_really_writable()` +- ``load_class()`` +- ``get_config()`` +- :php:func:`config_item()` +- :php:func:`show_error()` +- :php:func:`show_404()` +- :php:func:`log_message()` +- :php:func:`get_mimes()` +- :php:func:`html_escape()` +- :php:func:`get_instance()` +- ``_exception_handler()`` +- ``_stringify_attributes()`` Variables --------- -- $config -- $mimes -- $lang +- ``$config`` +- ``$db`` +- ``$lang`` Constants --------- @@ -62,5 +66,4 @@ Constants - FOPEN_WRITE_CREATE - FOPEN_READ_WRITE_CREATE - FOPEN_WRITE_CREATE_STRICT -- FOPEN_READ_WRITE_CREATE_STRICT - +- FOPEN_READ_WRITE_CREATE_STRICT \ 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 e6174cc0d..2a0332088 100644 --- a/user_guide_src/source/general/routing.rst +++ b/user_guide_src/source/general/routing.rst @@ -9,34 +9,34 @@ normally follow this pattern:: example.com/class/function/id/ In some instances, however, you may want to remap this relationship so -that a different class/function can be called instead of the one +that a different class/method can be called instead of the one corresponding to the URL. -For example, lets say you want your URLs to have this prototype: +For example, lets say you want your URLs to have this prototype:: -example.com/product/1/ -example.com/product/2/ -example.com/product/3/ -example.com/product/4/ + example.com/product/1/ + example.com/product/2/ + example.com/product/3/ + example.com/product/4/ -Normally the second segment of the URL is reserved for the function -name, but in the example above it instead has a product ID. To overcome -this, CodeIgniter allows you to remap the URI handler. +Normally the second segment of the URL is reserved for the method +name, but in the example above it instead has a product ID. To +overcome this, CodeIgniter allows you to remap the URI handler. Setting your own routing rules ============================== -Routing rules are defined in your application/config/routes.php file. In -it you'll see an array called $route that permits you to specify your -own routing criteria. Routes can either be specified using wildcards or -Regular Expressions. +Routing rules are defined in your *application/config/routes.php* file. +In it you'll see an array called ``$route`` that permits you to specify +your own routing criteria. Routes can either be specified using wildcards +or Regular Expressions. Wildcards ========= A typical wildcard route might look something like this:: - $route['product/:num'] = "catalog/product_lookup"; + $route['product/:num'] = 'catalog/product_lookup'; In a route, the array key contains the URI to be matched, while the array value contains the destination it should be re-routed to. In the @@ -66,21 +66,21 @@ Examples Here are a few routing examples:: - $route['journals'] = "blogs"; + $route['journals'] = 'blogs'; A URL containing the word "journals" in the first segment will be remapped to the "blogs" class. :: - $route['blog/joe'] = "blogs/users/34"; + $route['blog/joe'] = 'blogs/users/34'; A URL containing the segments blog/joe will be remapped to the "blogs" class and the "users" method. The ID will be set to "34". :: - $route['product/(:any)'] = "catalog/product_lookup"; + $route['product/(:any)'] = 'catalog/product_lookup'; A URL with "product" as the first segment, and anything in the second will be remapped to the "catalog" class and the "product_lookup" @@ -88,12 +88,12 @@ method. :: - $route['product/(:num)'] = "catalog/product_lookup_by_id/$1"; + $route['product/(:num)'] = 'catalog/product_lookup_by_id/$1'; A URL with "product" as the first segment, and a number in the second will be remapped to the "catalog" class and the "product_lookup_by_id" method passing in the match as a variable to -the function. +the method. .. important:: Do not use leading/trailing slashes. @@ -111,7 +111,7 @@ A typical RegEx route might look something like this:: $route['products/([a-z]+)/(\d+)'] = '$1/id_$2'; In the above example, a URI similar to products/shirts/123 would instead -call the shirts controller class and the id_123 method. +call the "shirts" controller class and the "id_123" method. With regular expressions, you can also catch a segment containing a forward slash ('/'), which would usually represent the delimiter between @@ -122,7 +122,7 @@ page after they log in, you may find this example useful:: $route['login/(.+)'] = 'auth/login/$1'; -That will call the auth controller class and its ``login()`` method, +That will call the "auth" controller class and its ``login()`` method, passing everything contained in the URI after *login/* as a parameter. For those of you who don't know regular expressions and want to learn @@ -134,12 +134,12 @@ might be a good starting point. Callbacks ========= -If you are using PHP >= 5.3 you can use callbacks in place of the normal routing -rules to process the back-references. Example:: +If you are using PHP >= 5.3 you can use callbacks in place of the normal +routing rules to process the back-references. Example:: $route['products/([a-z]+)/edit/(\d+)'] = function ($product_type, $id) { - return "catalog/product_edit/" . strtolower($product_type) . "/" . $id; + return 'catalog/product_edit/' . strtolower($product_type) . '/' . $id; }; Reserved Routes @@ -161,7 +161,7 @@ appear by default. This route indicates which controller class should be loaded if the requested controller is not found. It will override the default 404 -error page. It won't affect to the show_404() function, which will +error page. It won't affect to the ``show_404()`` function, which will continue loading the default *error_404.php* file at *application/errors/error_404.php*. diff --git a/user_guide_src/source/general/security.rst b/user_guide_src/source/general/security.rst index 4d7a213d1..984ca840b 100644 --- a/user_guide_src/source/general/security.rst +++ b/user_guide_src/source/general/security.rst @@ -13,38 +13,40 @@ in your URI strings in order to help minimize the possibility that malicious data can be passed to your application. URIs may only contain the following: -- Alpha-numeric text +- Alpha-numeric text (latin characters only) - Tilde: ~ - Period: . - Colon: : - Underscore: \_ - Dash: - +- Pipe: | Register_globals ================= During system initialization all global variables are unset, except -those found in the $_GET, $_POST, and $_COOKIE arrays. The unsetting -routine is effectively the same as register_globals = off. +those found in the ``$_GET``, ``$_POST``, and ``$_COOKIE`` arrays. +The unsetting routine is effectively the same as +*register_globals = off*. -error_reporting -================ +display_errors +============== -In production environments, it is typically desirable to disable PHP's -error reporting by setting the internal error_reporting flag to a value +In production environments, it is typically desirable to "disable" PHP's +error reporting by setting the internal *display_errors* flag to a value of 0. This disables native PHP errors from being rendered as output, which may potentially contain sensitive information. Setting CodeIgniter's **ENVIRONMENT** constant in index.php to a value of **\'production\'** will turn off these errors. In development mode, it is recommended that a value of 'development' is used. More information -about differentiating between environments can be found on the :doc:`Handling -Environments ` page. +about differentiating between environments can be found on the +:doc:`Handling Environments ` page. magic_quotes_runtime -====================== +==================== -The magic_quotes_runtime directive is turned off during system +The *magic_quotes_runtime* directive is turned off during system initialization so that you don't have to remove slashes when retrieving data from your database. @@ -68,7 +70,7 @@ XSS Filtering ============= CodeIgniter comes with a Cross Site Scripting filter. This filter -looks for commonly used techniques to embed malicious Javascript into +looks for commonly used techniques to embed malicious JavaScript into your data, or other types of code that attempt to hijack cookies or do other malicious things. The XSS Filter is described :doc:`here <../libraries/security>`. @@ -76,15 +78,32 @@ do other malicious things. The XSS Filter is described Validate the data ================= -CodeIgniter has a :doc:`Form Validation -Class <../libraries/form_validation>` that assists you in +CodeIgniter has a :doc:`Form Validation Library +<../libraries/form_validation>` that assists you in validating, filtering, and prepping your data. Escape all data before database insertion ========================================= Never insert information into your database without escaping it. -Please see the section that discusses -:doc:`queries <../database/queries>` for more information. +Please see the section that discusses :doc:`database queries +<../database/queries>` for more information. +Hide your files +=============== +Another good security practice is to only leave your *index.php* +and "assets" (e.g. .js, css and image files) under your server's +*webroot* directory (most commonly named "htdocs/"). These are +the only files that you would need to be accessible from the web. + +Allowing your visitors to see anything else would potentially +allow them to access sensitive data, execute scripts, etc. + +If you're not allowed to do that, you can try using a .htaccess +file to restrict access to those resources. + +CodeIgniter will have an index.html file in all of its +directories in an attempt to hide some of this data, but have +it in mind that this is not enough to prevent a serious +attacker. \ 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 925954c03..7c0a59791 100644 --- a/user_guide_src/source/general/styleguide.rst +++ b/user_guide_src/source/general/styleguide.rst @@ -168,11 +168,11 @@ picked up by IDEs:: /** * Encodes string for use in XML * - * @param string + * @param string $str Input string * @return string */ function xml_encode($str) - + :: /** @@ -180,9 +180,7 @@ picked up by IDEs:: * * @var array */ - public $data - - + public $data = array(); Use single line comments within code, leaving a blank line between large comment blocks and code. @@ -308,8 +306,8 @@ Use **===** and **!==** as necessary. } -See also information regarding -`typecasting `_, +See also information regarding `typecasting +`_, which can be quite useful. Typecasting has a slightly different effect which may be desirable. When casting a variable as a string, for instance, NULL and boolean FALSE variables become empty strings, 0 (and @@ -338,7 +336,6 @@ begin before CodeIgniter outputs its content, leading to errors and an inability for CodeIgniter to send proper headers. In the examples below, select the text with your mouse to reveal the incorrect whitespace. - Compatibility ============= @@ -559,16 +556,16 @@ code abstraction, should be prefixed with an underscore. :: - convert_text() // public method - _convert_text() // private method + public function convert_text() + private function _convert_text() PHP Errors ========== Code must run error free and not rely on warnings and notices to be hidden to meet this requirement. For instance, never access a variable -that you did not set yourself (such as $_POST array keys) without first -checking to see that it isset(). +that you did not set yourself (such as ``$_POST`` array keys) without first +checking to see that it ``isset()``. Make sure that while developing your add-on, error reporting is enabled for ALL users, and that display_errors is enabled in the PHP @@ -579,22 +576,22 @@ environment. You can check this setting with:: exit "Enabled"; } -On some servers where display_errors is disabled, and you do not have +On some servers where *display_errors* is disabled, and you do not have the ability to change this in the php.ini, you can often enable it with:: ini_set('display_errors', 1); -**NOTE:** Setting the -`display_errors `_ -setting with ini_set() at runtime is not identical to having it enabled -in the PHP environment. Namely, it will not have any effect if the -script has fatal errors +.. note:: Setting the `display_errors + `_ + setting with ``ini_set()`` at runtime is not identical to having + it enabled in the PHP environment. Namely, it will not have any + effect if the script has fatal errors. Short Open Tags =============== Always use full PHP opening tags, in case a server does not have -short_open_tag enabled. +*short_open_tag* enabled. **INCORRECT**:: @@ -606,6 +603,8 @@ short_open_tag enabled. +.. note:: PHP 5.4 will always have the **` and the :doc:`URL Helper <../helpers/url_helper>` -contain functions that make it easy to work with your URI data. In addition, -your URLs can be remapped using the :doc:`URI Routing ` feature for -more flexibility. +The :doc:`URI Library <../libraries/uri>` and the :doc:`URL Helper +<../helpers/url_helper>` contain functions that make it easy to work +with your URI data. In addition, your URLs can be remapped using the +:doc:`URI Routing ` feature for more flexibility. Friendly URLs ============= @@ -58,7 +57,7 @@ By default, the **index.php** file will be included in your URLs:: example.com/index.php/news/article/my_article -If your Apache server has mod_rewrite enabled, you can easily remove this +If your Apache server has *mod_rewrite* enabled, you can easily remove this file by using a .htaccess file with some simple rules. Here is an example of such a file, using the "negative" method in which everything is redirected except the specified items: @@ -73,7 +72,10 @@ except the specified items: In the above example, any HTTP request other than those for existing directories and existing files is treated as a request for your index.php file. -.. note:: Note: These specific rules might not work for all server configurations. +.. note:: These specific rules might not work for all server configurations. + +.. note:: Make sure to also exclude from the above rule any assets that you + might need to be accessible from the outside world. Adding a URL Suffix =================== @@ -110,7 +112,7 @@ active. Your controllers and functions will then be accessible using the index.php?c=controller&m=method -.. note:: If you are using query strings you will have to build - your own URLs, rather than utilizing the URL helpers (and other helpers - that generate URLs, like some of the form helpers) as these are designed - to work with segment based URLs. \ No newline at end of file +.. note:: If you are using query strings you will have to build your own + URLs, rather than utilizing the URL helpers (and other helpers + that generate URLs, like some of the form helpers) as these are + designed to work with segment based URLs. \ No newline at end of file diff --git a/user_guide_src/source/general/views.rst b/user_guide_src/source/general/views.rst index 9b7c9daaa..4b1ab3c34 100644 --- a/user_guide_src/source/general/views.rst +++ b/user_guide_src/source/general/views.rst @@ -31,20 +31,22 @@ in it:: -Then save the file in your application/views/ folder. +Then save the file in your *application/views/* directory. Loading a View ============== -To load a particular view file you will use the following function:: +To load a particular view file you will use the following method:: $this->load->view('name'); -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. +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 -replace the echo statement with the view loading function:: +replace the echo statement with the view loading method:: load->view('blogview'); } } - ?> If you visit your site using the URL you did earlier you should see your new view. The URL was similar to this:: @@ -65,7 +66,7 @@ Loading multiple views ====================== CodeIgniter will intelligently handle multiple calls to -$this->load->view from within a controller. If more than one call +``$this->load->view()`` from within a controller. If more than one call happens they will be appended together. For example, you may wish to have a header view, a menu view, a content view, and a footer view. That might look something like this:: @@ -84,32 +85,31 @@ might look something like this:: } } - ?> In the example above, we are using "dynamically added data", which you will see below. -Storing Views within Sub-folders -================================ +Storing Views within Sub-directories +==================================== -Your view files can also be stored within sub-folders if you prefer that -type of organization. When doing so you will need to include the folder -name loading the view. Example:: +Your view files can also be stored within sub-directories if you prefer +that type of organization. When doing so you will need to include the +directory name loading the view. Example:: - $this->load->view('folder_name/file_name'); + $this->load->view('directory_name/file_name'); Adding Dynamic Data to the View =============================== Data is passed from the controller to the view by way of an **array** or -an **object** in the second parameter of the view loading function. Here +an **object** in the second parameter of the view loading method. Here is an example using an array:: $data = array( - 'title' => 'My Title', - 'heading' => 'My Heading', - 'message' => 'My Message' - ); + 'title' => 'My Title', + 'heading' => 'My Heading', + 'message' => 'My Message' + ); $this->load->view('blogview', $data); @@ -118,8 +118,8 @@ And here's an example using an object:: $data = new Someclass(); $this->load->view('blogview', $data); -Note: If you use an object, the class variables will be turned into -array elements. +.. note:: If you use an object, the class variables will be turned + into array elements. Let's try it with your controller file. Open it add this code:: @@ -134,7 +134,6 @@ Let's try it with your controller file. Open it add this code:: $this->load->view('blogview', $data); } } - ?> Now open your view file and change the text to variables that correspond to the array keys in your data:: @@ -174,7 +173,6 @@ Here's a simple example. Add this to your controller:: $this->load->view('blogview', $data); } } - ?> Now open your view file and create a loop:: @@ -200,17 +198,16 @@ Now open your view file and create a loop:: .. note:: You'll notice that in the example above we are using PHP's alternative syntax. If you are not familiar with it you can read about - it :doc:`here `. + it :doc:`here `. Returning views as data ======================= There is a third **optional** parameter lets you change the behavior of -the function so that it returns data as a string rather than sending it +the method so that it returns data as a string rather than sending it to your browser. This can be useful if you want to process the data in -some way. If you set the parameter to true (boolean) it will return +some way. If you set the parameter to TRUE (boolean) it will return data. The default behavior is false, which sends it to your browser. Remember to assign it to a variable if you want the data returned:: - $string = $this->load->view('myfile', '', true); - + $string = $this->load->view('myfile', '', TRUE); \ No newline at end of file diff --git a/user_guide_src/source/general/welcome.rst b/user_guide_src/source/general/welcome.rst index b28c3bcc2..b6f473c2b 100644 --- a/user_guide_src/source/general/welcome.rst +++ b/user_guide_src/source/general/welcome.rst @@ -29,4 +29,4 @@ CodeIgniter is right for you if: - You do not want to be forced to learn a templating language (although a template parser is optionally available if you desire one). - You eschew complexity, favoring simple solutions. -- You need clear, thorough documentation. +- You need clear, thorough documentation. \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 93f5c5d2f9fc385c1617c125cfdf1822e6d7aee2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 22 Nov 2012 13:26:07 +0200 Subject: [ci skip] Fix a typo in the styleguide --- user_guide_src/source/general/styleguide.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'user_guide_src/source/general') diff --git a/user_guide_src/source/general/styleguide.rst b/user_guide_src/source/general/styleguide.rst index 7c0a59791..99bc056f7 100644 --- a/user_guide_src/source/general/styleguide.rst +++ b/user_guide_src/source/general/styleguide.rst @@ -52,7 +52,7 @@ whether introduced by the developer, user, or an FTP application, can cause unwanted output, PHP errors, or if the latter are suppressed, blank pages. For this reason, all PHP files should **OMIT** the closing PHP tag, and instead use a comment block to mark the end of file and -it's location relative to the application root. This allows you to still +its location relative to the application root. This allows you to still identify a file as being complete and not truncated. **INCORRECT**:: -- cgit v1.2.3-24-g4f1b From b37d2bc462af918276111d0439592aa445ac6277 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 30 Nov 2012 02:19:35 +0200 Subject: Add CI_Output::delete_cache() (an improved version of PR #609) --- user_guide_src/source/general/caching.rst | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'user_guide_src/source/general') diff --git a/user_guide_src/source/general/caching.rst b/user_guide_src/source/general/caching.rst index c40f652ac..48385d6c9 100644 --- a/user_guide_src/source/general/caching.rst +++ b/user_guide_src/source/general/caching.rst @@ -56,5 +56,13 @@ If you no longer wish to cache a file you can remove the caching tag and it will no longer be refreshed when it expires. .. note:: Removing the tag will not delete the cache immediately. It will - have to expire normally. If you need to remove it earlier you - will need to manually delete it from your cache directory. \ No newline at end of file + have to expire normally. + +If you need to manually delete the cache, you can use the ``delete_cache()`` +method:: + + // Deletes cache for the currently requested URI + $this->output->delete_cache(); + + // Deletes cache for /foo/bar + $this->output->delete_cache('/foo/bar'); \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 838a9d69a9139b6bcd6f8765fdd2d58b929e70ad Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 3 Dec 2012 14:37:47 +0200 Subject: [ci skip] Cleaned some spaces --- user_guide_src/source/general/common_functions.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'user_guide_src/source/general') diff --git a/user_guide_src/source/general/common_functions.rst b/user_guide_src/source/general/common_functions.rst index 66dabd95e..7917d3239 100644 --- a/user_guide_src/source/general/common_functions.rst +++ b/user_guide_src/source/general/common_functions.rst @@ -178,8 +178,8 @@ is_https() Returns TRUE if a secure (HTTPS) connection is used and FALSE in any other case (including non-HTTP requests). -function_usable($function_name) -=============================== +function_usable() +================= .. php:function:: function_usable($function_name) -- cgit v1.2.3-24-g4f1b