Skip to content

Commit fa31844

Browse files
committed
docs: fix description for helper loading
and add "Auto-Discovery and Composer Packages"
1 parent bb1369a commit fa31844

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

user_guide_src/source/general/helpers.rst

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ in your :doc:`controller <../incoming/controllers>` and
2828
:doc:`views <../outgoing/views>`.
2929

3030
Helpers are typically stored in your **system/Helpers**, or
31-
**app/Helpers** directory. CodeIgniter will look first in your
32-
**app/Helpers** directory. If the directory does not exist or the
33-
specified helper is not located there CI will instead look in your
34-
global **system/Helpers** directory.
31+
**app/Helpers** directory.
3532

36-
****************
37-
Loading a Helper
38-
****************
33+
***************
34+
Loading Helpers
35+
***************
3936

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

39+
Loading a Helper
40+
================
41+
4242
Loading a helper file is quite simple using the following method:
4343

4444
.. literalinclude:: helpers/001.php
@@ -58,6 +58,23 @@ For example, to load the **Cookie Helper** file, which is named
5858
.. note:: The Helper loading method above does not return a value, so
5959
don't try to assign it to a variable. Just use it as shown.
6060

61+
Auto-Discovery and Composer Packages
62+
------------------------------------
63+
64+
By default, CodeIgniter will search for the helper files in all defined namespaces
65+
by :ref:`auto-discovery`.
66+
You can check your defined namespaces by the spark command. See :ref:`confirming-namespaces`.
67+
68+
If you use many Composer packages, you will have many defined namespaces.
69+
CodeIgniter will scan all namespaces by default.
70+
71+
To avoid wasting time scanning for irrelevant Composer packages, you can manually
72+
specify packages for Auto-Discovery. See :ref:`modules-specify-composer-packages`
73+
for details.
74+
75+
Or you can :ref:`specify a namespace <helpers-loading-from-specified-namespace>`
76+
for a helper that you want to load.
77+
6178
Loading Multiple Helpers
6279
========================
6380

@@ -81,14 +98,14 @@ it.
8198
However if you want to load in your controller constructor, you can use the ``$helpers``
8299
property in Controller instead. See :ref:`Controllers <controllers-helpers>`.
83100

84-
.. _helpers-loading-from-non-standard-locations:
101+
.. _helpers-loading-from-specified-namespace:
85102

86-
Loading from Non-standard Locations
87-
===================================
103+
Loading from Specified Namespace
104+
================================
88105

89106
Helpers can be loaded from directories outside of **app/Helpers** and
90-
**system/Helpers**, as long as that path can be found through a namespace that
91-
has been set up within the PSR-4 section of the :doc:`Autoloader config file <../concepts/autoloader>`.
107+
**system/Helpers**, as long as that path can be found in defined namespaces.
108+
92109
You would prefix the name of the Helper with the namespace that it can be located
93110
in. Within that namespaced directory, the loader expects it to live within a
94111
sub-directory named **Helpers**. An example will help understand this.

user_guide_src/source/general/modules.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ directory:
246246

247247
.. literalinclude:: modules/009.php
248248

249-
You can specify namespaces. See :ref:`helpers-loading-from-non-standard-locations` for details.
249+
You can specify namespaces. See :ref:`helpers-loading-from-specified-namespace` for details.
250250

251251
Language Files
252252
==============

0 commit comments

Comments
 (0)