summaryrefslogtreecommitdiffstats
path: root/user_guide_src/source/general/helpers.rst
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-11-09 16:25:00 +0100
committerAndrey Andreev <narf@bofh.bg>2012-11-09 16:25:00 +0100
commit16a704ce8a1449cbee22fb13bd32508c975fac9f (patch)
tree524dbee290643a7dc762ddc505a0216bc871a6ef /user_guide_src/source/general/helpers.rst
parent1bc30260d8bd35a958f3d7b899f68c95d69c9e75 (diff)
[ci skip] Polish docs in user_guide_src/source/general/
Diffstat (limited to 'user_guide_src/source/general/helpers.rst')
-rw-r--r--user_guide_src/source/general/helpers.rst58
1 files changed, 30 insertions, 28 deletions
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::
<?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. \ No newline at end of file