@@ -28,17 +28,17 @@ in your :doc:`controller <../incoming/controllers>` and
2828:doc: `views <../outgoing/views >`.
2929
3030Helpers 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+
4242Loading 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+
6178Loading Multiple Helpers
6279========================
6380
8198However if you want to load in your controller constructor, you can use the ``$helpers ``
8299property 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
89106Helpers 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+
92109You would prefix the name of the Helper with the namespace that it can be located
93110in. Within that namespaced directory, the loader expects it to live within a
94111sub-directory named **Helpers **. An example will help understand this.
0 commit comments