Skip to content

Commit 2a5dad2

Browse files
authored
Merge pull request #6927 from kenjis/fix-docs-helpers
docs: improve helpers
2 parents bcd8054 + ca2fb2d commit 2a5dad2

2 files changed

Lines changed: 30 additions & 14 deletions

File tree

user_guide_src/source/general/helpers.rst

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ global **system/Helpers** directory.
3232
Loading a Helper
3333
================
3434

35+
.. note:: The URL helper is always loaded so you do not need to load it yourself.
36+
3537
Loading a helper file is quite simple using the following method:
3638

3739
.. literalinclude:: helpers/001.php
@@ -44,22 +46,31 @@ For example, to load the **Cookie Helper** file, which is named
4446

4547
.. literalinclude:: helpers/002.php
4648

49+
.. note:: The Helper loading method above does not return a value, so
50+
don't try to assign it to a variable. Just use it as shown.
51+
52+
Loading Multiple Helpers
53+
------------------------
54+
4755
If you need to load more than one helper at a time, you can pass
4856
an array of file names in and all of them will be loaded:
4957

5058
.. literalinclude:: helpers/003.php
5159

60+
Loading in a Controller
61+
-----------------------
62+
5263
A helper can be loaded anywhere within your controller methods (or
5364
even within your View files, although that's not a good practice), as
54-
long as you load it before you use it. You can load your helpers in your
65+
long as you load it before you use it.
66+
67+
You can load your helpers in your
5568
controller constructor so that they become available automatically in
56-
any function, or you can load a helper in a specific function that needs
69+
any method, or you can load a helper in a specific method that needs
5770
it.
5871

59-
.. note:: The Helper loading method above does not return a value, so
60-
don't try to assign it to a variable. Just use it as shown.
61-
62-
.. note:: The URL helper is always loaded so you do not need to load it yourself.
72+
However if you want to load in your controller constructor, you can use the ``$helpers``
73+
property in Controller instead. See :ref:`Controllers <controllers-helpers>`.
6374

6475
Loading from Non-standard Locations
6576
-----------------------------------
@@ -73,9 +84,9 @@ sub-directory named **Helpers**. An example will help understand this.
7384

7485
For this example, assume that we have grouped together all of our Blog-related
7586
code into its own namespace, ``Example\Blog``. The files exist on our server at
76-
**/Modules/Blog/**. So, we would put our Helper files for the blog module in
77-
**/Modules/Blog/Helpers/**. A **blog_helper** file would be at
78-
**/Modules/Blog/Helpers/blog_helper.php**. Within our controller we could
87+
**Modules/Blog/**. So, we would put our Helper files for the blog module in
88+
**Modules/Blog/Helpers/**. A **blog_helper** file would be at
89+
**Modules/Blog/Helpers/blog_helper.php**. Within our controller we could
7990
use the following command to load the helper for us:
8091

8192
.. literalinclude:: helpers/004.php
@@ -89,7 +100,7 @@ Using a Helper
89100
Once you've loaded the Helper File containing the function you intend to
90101
use, you'll call it the way you would a standard PHP function.
91102

92-
For example, to create a link using the ``anchor()`` function in one of
103+
For example, to create a link using the :php:func:`anchor()` function in one of
93104
your view files you would do this:
94105

95106
.. literalinclude:: helpers/005.php
@@ -119,7 +130,7 @@ functions:
119130

120131
.. literalinclude:: helpers/006.php
121132

122-
The ``helper()`` method will scan through all PSR-4 namespaces defined in **app/Config/Autoload.php**
133+
The ``helper()`` function will scan through all PSR-4 namespaces defined in **app/Config/Autoload.php**
123134
and load in ALL matching helpers of the same name. This allows any module's helpers
124135
to be loaded, as well as any helpers you've created specifically for this application. The load order
125136
is as follows:

user_guide_src/source/incoming/controllers.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,26 @@ Included Properties
3535

3636
The CodeIgniter's Controller provides these properties.
3737

38-
**Request Object**
38+
Request Object
39+
==============
3940

4041
The application's main :doc:`Request Instance </incoming/incomingrequest>` is always available
4142
as a class property, ``$this->request``.
4243

43-
**Response Object**
44+
Response Object
45+
===============
4446

4547
The application's main :doc:`Response Instance </outgoing/response>` is always available
4648
as a class property, ``$this->response``.
4749

48-
**Logger Object**
50+
Logger Object
51+
=============
4952

5053
An instance of the :doc:`Logger <../general/logging>` class is available as a class property,
5154
``$this->logger``.
5255

56+
.. _controllers-helpers:
57+
5358
Helpers
5459
=======
5560

0 commit comments

Comments
 (0)