Skip to content

Commit 57d0ea8

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into 4.3
Conflicts: user_guide_src/source/general/helpers.rst
2 parents 6f1cb11 + 1973c35 commit 57d0ea8

1 file changed

Lines changed: 27 additions & 13 deletions

File tree

user_guide_src/source/general/helpers.rst

Lines changed: 27 additions & 13 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
@@ -103,7 +112,7 @@ You can also use the following way:
103112
.. _auto-loading-helpers:
104113

105114
Auto-loading Helpers
106-
--------------------
115+
====================
107116

108117
.. versionadded:: 4.3.0
109118

@@ -112,8 +121,9 @@ you can tell CodeIgniter to auto-load it during system initialization.
112121
This is done by opening the **app/Config/Autoload.php** file
113122
and adding the helper to the ``$helpers`` property.
114123

124+
**************
115125
Using a Helper
116-
==============
126+
**************
117127

118128
Once you've loaded the Helper File containing the function you intend to
119129
use, you'll call it the way you would a standard PHP function.
@@ -126,8 +136,9 @@ your view files you would do this:
126136
Where ``Click Here`` is the name of the link, and ``blog/comments`` is the
127137
URI to the controller/method you wish to link to.
128138

139+
*******************
129140
"Extending" Helpers
130-
===================
141+
*******************
131142

132143
To "extend" Helpers, create a file in your **app/Helpers/** folder
133144
with an identical name to the existing Helper.
@@ -148,7 +159,9 @@ functions:
148159

149160
.. literalinclude:: helpers/006.php
150161

151-
The ``helper()`` function will scan through all PSR-4 namespaces defined in **app/Config/Autoload.php**
162+
.. important:: Do not specify the namespace ``App\Helpers``.
163+
164+
The :php:func:`helper()` function will scan through all PSR-4 namespaces defined in **app/Config/Autoload.php**
152165
and load in ALL matching helpers of the same name. This allows any module's helpers
153166
to be loaded, as well as any helpers you've created specifically for this application. The load order
154167
is as follows:
@@ -157,8 +170,9 @@ is as follows:
157170
2. {namespace}/Helpers - All namespaces are looped through in the order they are defined.
158171
3. system/Helpers - The base file is loaded last
159172

173+
*********
160174
Now What?
161-
=========
175+
*********
162176

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

0 commit comments

Comments
 (0)