Skip to content

Commit 1973c35

Browse files
authored
Merge pull request #7032 from kenjis/fix-docs-helpers.rst
docs: improve helpers.rst
2 parents 487ec6d + 6f9030a commit 1973c35

1 file changed

Lines changed: 26 additions & 12 deletions

File tree

user_guide_src/source/general/helpers.rst

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@
22
Helper Functions
33
################
44

5+
.. contents::
6+
:local:
7+
:depth: 2
8+
9+
*****************
10+
What are Helpers?
11+
*****************
12+
513
Helpers, as the name suggests, help you with tasks. Each helper file is
614
simply a collection of functions in a particular category. There are **URL
715
Helpers**, that assist in creating links, there are **Form Helpers** that help
816
you create form elements, **Text Helpers** perform various text formatting
917
routines, **Cookie Helpers** set and read cookies, **File Helpers** help you
1018
deal with files, etc.
1119

12-
.. contents::
13-
:local:
14-
:depth: 2
15-
1620
Unlike most other systems in CodeIgniter, Helpers are not written in an
1721
Object Oriented format. They are simple, procedural functions. Each
1822
helper function performs one specific task, with no dependence on other
@@ -29,8 +33,9 @@ Helpers are typically stored in your **system/Helpers**, or
2933
specified helper is not located there CI will instead look in your
3034
global **system/Helpers** directory.
3135

36+
****************
3237
Loading a Helper
33-
================
38+
****************
3439

3540
.. note:: The URL helper is always loaded so you do not need to load it yourself.
3641

@@ -41,6 +46,10 @@ Loading a helper file is quite simple using the following method:
4146
Where ``name`` is the file name of the helper, without the "**.php**" file
4247
extension or the "**_helper**" part.
4348

49+
.. important:: CodeIgniter helper file names are all lowercase.
50+
Therefore, ``helper('Name')`` will not work on case-sensitive file systems
51+
such as Linux.
52+
4453
For example, to load the **Cookie Helper** file, which is named
4554
**cookie_helper.php**, you would do this:
4655

@@ -50,15 +59,15 @@ For example, to load the **Cookie Helper** file, which is named
5059
don't try to assign it to a variable. Just use it as shown.
5160

5261
Loading Multiple Helpers
53-
------------------------
62+
========================
5463

5564
If you need to load more than one helper at a time, you can pass
5665
an array of file names in and all of them will be loaded:
5766

5867
.. literalinclude:: helpers/003.php
5968

6069
Loading in a Controller
61-
-----------------------
70+
=======================
6271

6372
A helper can be loaded anywhere within your controller methods (or
6473
even within your View files, although that's not a good practice), as
@@ -75,7 +84,7 @@ property in Controller instead. See :ref:`Controllers <controllers-helpers>`.
7584
.. _helpers-loading-from-non-standard-locations:
7685

7786
Loading from Non-standard Locations
78-
-----------------------------------
87+
===================================
7988

8089
Helpers can be loaded from directories outside of **app/Helpers** and
8190
**system/Helpers**, as long as that path can be found through a namespace that
@@ -100,8 +109,9 @@ You can also use the following way:
100109
.. note:: The functions within files loaded this way are not truly namespaced.
101110
The namespace is simply used as a convenient way to locate the files.
102111

112+
**************
103113
Using a Helper
104-
==============
114+
**************
105115

106116
Once you've loaded the Helper File containing the function you intend to
107117
use, you'll call it the way you would a standard PHP function.
@@ -114,8 +124,9 @@ your view files you would do this:
114124
Where ``Click Here`` is the name of the link, and ``blog/comments`` is the
115125
URI to the controller/method you wish to link to.
116126

127+
*******************
117128
"Extending" Helpers
118-
===================
129+
*******************
119130

120131
To "extend" Helpers, create a file in your **app/Helpers/** folder
121132
with an identical name to the existing Helper.
@@ -136,7 +147,9 @@ functions:
136147

137148
.. literalinclude:: helpers/006.php
138149

139-
The ``helper()`` function will scan through all PSR-4 namespaces defined in **app/Config/Autoload.php**
150+
.. important:: Do not specify the namespace ``App\Helpers``.
151+
152+
The :php:func:`helper()` function will scan through all PSR-4 namespaces defined in **app/Config/Autoload.php**
140153
and load in ALL matching helpers of the same name. This allows any module's helpers
141154
to be loaded, as well as any helpers you've created specifically for this application. The load order
142155
is as follows:
@@ -145,8 +158,9 @@ is as follows:
145158
2. {namespace}/Helpers - All namespaces are looped through in the order they are defined.
146159
3. system/Helpers - The base file is loaded last
147160

161+
*********
148162
Now What?
149-
=========
163+
*********
150164

151165
In the Table of Contents, you'll find a list of all the available :doc:`Helpers <../helpers/index>`.
152166
Browse each one to see what they do.

0 commit comments

Comments
 (0)