Skip to content
Browse files

[ci skip] Polish docs in user_guide_src/source/general/

  • Loading branch information...
1 parent 1bc3026 commit 16a704ce8a1449cbee22fb13bd32508c975fac9f @narfbg narfbg committed Nov 9, 2012
Showing with 587 additions and 473 deletions.
  1. +1 −1 user_guide_src/source/contributing/index.rst
  2. +10 −11 user_guide_src/source/general/alternative_php.rst
  3. +50 −11 user_guide_src/source/general/ancillary_classes.rst
  4. +9 −9 user_guide_src/source/general/autoloader.rst
  5. +16 −14 user_guide_src/source/general/caching.rst
  6. +7 −7 user_guide_src/source/general/cli.rst
  7. +41 −43 user_guide_src/source/general/controllers.rst
  8. +20 −20 user_guide_src/source/general/core_classes.rst
  9. +3 −2 user_guide_src/source/general/creating_drivers.rst
  10. +60 −33 user_guide_src/source/general/creating_libraries.rst
  11. +1 −1 user_guide_src/source/general/credits.rst
  12. +8 −8 user_guide_src/source/general/drivers.rst
  13. +3 −3 user_guide_src/source/general/environments.rst
  14. +44 −22 user_guide_src/source/general/errors.rst
  15. +30 −28 user_guide_src/source/general/helpers.rst
  16. +37 −36 user_guide_src/source/general/hooks.rst
  17. +1 −1 user_guide_src/source/general/index.rst
  18. +12 −11 user_guide_src/source/general/libraries.rst
  19. +21 −23 user_guide_src/source/general/managing_apps.rst
  20. +48 −49 user_guide_src/source/general/models.rst
  21. +14 −14 user_guide_src/source/general/profiling.rst
  22. +10 −4 user_guide_src/source/general/requirements.rst
  23. +22 −19 user_guide_src/source/general/reserved_names.rst
  24. +25 −25 user_guide_src/source/general/routing.rst
  25. +35 −16 user_guide_src/source/general/security.rst
  26. +20 −22 user_guide_src/source/general/styleguide.rst
  27. +13 −11 user_guide_src/source/general/urls.rst
  28. +25 −28 user_guide_src/source/general/views.rst
  29. +1 −1 user_guide_src/source/general/welcome.rst
View
2 user_guide_src/source/contributing/index.rst
@@ -102,4 +102,4 @@ it.
By signing your work in this manner, you certify to a "Developer's Certificate
or Origin". The current version of this certificate is in the :doc:`/DCO` file
-in the root of this documentation.
+in the root of this documentation.
View
21 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``::
<ul>
<?php foreach ($todo as $item): ?>
- <li><?=$item?></li>
+ <li><?=$item?></li>
<?php endforeach; ?>
@@ -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::
- <?php if ($username == 'sally'): ?>
+ <?php if ($username === 'sally'): ?>
- <h3>Hi Sally</h3>
+ <h3>Hi Sally</h3>
- <?php elseif ($username == 'joe'): ?>
+ <?php elseif ($username === 'joe'): ?>
- <h3>Hi Joe</h3>
+ <h3>Hi Joe</h3>
<?php else: ?>
- <h3>Hi unknown user</h3>
-
- <?php endif; ?>
+ <h3>Hi unknown user</h3>
+ <?php endif; ?>
View
61 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.
View
18 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.
View
30 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.
View
14 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.
View
84 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::
<?php
class Blog extends CI_Controller {
}
- ?>
-
This is **not** valid::
<?php
class blog extends CI_Controller {
}
- ?>
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 <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() <http://php.net/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 <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::
<?php
class Blog extends CI_Controller {
@@ -307,7 +306,6 @@ manually call it.
// Your own constructor code
}
}
- ?>
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 <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!
View
40 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.
View
5 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()``.
View
93 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,17 +49,17 @@ Someclass purely as an example)::
class Someclass {
- public function some_function()
- {
- }
+ public function some_method()
+ {
+ }
}
/* End of file Someclass.php */
Using Your Class
================
-From within any of your :doc:`Controller <controllers>` functions you
+From within any of your :doc:`Controller <controllers>` 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,40 +86,38 @@ constructor::
If you use this feature you must set up your class constructor to expect
data::
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+ <?php defined('BASEPATH') OR exit('No direct script access allowed');
class Someclass {
- public function __construct($params)
- {
- // Do something with $params
- }
+ public function __construct($params)
+ {
+ // Do something with $params
+ }
}
- ?>
-
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.
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,31 +135,61 @@ 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.
+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
=============================================
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 {
}
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.
View
2 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.
View
16 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 <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 <creating_drivers>`.
+your own drivers <creating_drivers>`.
View
6 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.
View
66 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.
View
58 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,30 +40,32 @@ 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
========================
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::
<?php echo anchor('blog/comments', 'Click Here');?>
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.
View
73 user_guide_src/source/general/hooks.rst
@@ -16,40 +16,42 @@ 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
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.
View
2 user_guide_src/source/general/index.rst
@@ -29,4 +29,4 @@ General Topics
environments
alternative_php
security
- PHP Style Guide <styleguide>
+ PHP Style Guide <styleguide>
View
23 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 <controllers>` 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 <creating_libraries>`
+Please read the section of the user guide that discusses how to
+:doc:`create your own libraries <creating_libraries>`.
View
44 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.
View
97 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 <controllers>` functions. To load a model you will use
+:doc:`controller <controllers>` 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);
View
28 user_guide_src/source/general/profiling.rst
@@ -3,22 +3,22 @@ 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.
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 <controllers>` functions::
+To enable the profiler place the following line anywhere within your
+:doc:`Controller <controllers>` methods::
$this->output->enable_profiler(TRUE);
@@ -35,30 +35,30 @@ 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
========================================
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);
View
14 user_guide_src/source/general/requirements.rst
@@ -3,7 +3,13 @@ Server Requirements
###################
- `PHP <http://www.php.net/>`_ 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)
View
41 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
View
50 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,34 +66,34 @@ 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"
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*.
View
51 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 <environments>` page.
+about differentiating between environments can be found on the
+:doc:`Handling Environments <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,23 +70,40 @@ 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>`.
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.
View
42 user_guide_src/source/general/styleguide.rst
@@ -168,21 +168,19 @@ picked up by IDEs::
/**
* Encodes string for use in XML
*
- * @param string
+ * @param string $str Input string
* @return string
*/
function xml_encode($str)
-
+
::
/**
* Data for class manipulation
*
* @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 <http://us3.php.net/manual/en/language.types.type-juggling.php#language.types.typecasting>`_,
+See also information regarding `typecasting
+<http://php.net/manual/en/language.types.type-juggling.php#language.types.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 <http://us.php.net/manual/en/ref.errorfunc.php#ini.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
+ <http://php.net/manual/en/ref.errorfunc.php#ini.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.
<?php echo $foo; ?>
+.. note:: PHP 5.4 will always have the **<?=** tag available.
+
One Statement Per Line
======================
@@ -645,7 +644,7 @@ characters.
SQL Queries
===========