@@ -28,17 +28,17 @@ in your :doc:`controller <../incoming/controllers>` and
28
28
:doc: `views <../outgoing/views >`.
29
29
30
30
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.
35
32
36
- ****************
37
- Loading a Helper
38
- ****************
33
+ ***************
34
+ Loading Helpers
35
+ ***************
39
36
40
37
.. note :: The URL helper is always loaded so you do not need to load it yourself.
41
38
39
+ Loading a Helper
40
+ ================
41
+
42
42
Loading a helper file is quite simple using the following method:
43
43
44
44
.. literalinclude :: helpers/001.php
@@ -58,6 +58,23 @@ For example, to load the **Cookie Helper** file, which is named
58
58
.. note :: The Helper loading method above does not return a value, so
59
59
don't try to assign it to a variable. Just use it as shown.
60
60
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
+
61
78
Loading Multiple Helpers
62
79
========================
63
80
81
98
However if you want to load in your controller constructor, you can use the ``$helpers ``
82
99
property in Controller instead. See :ref: `Controllers <controllers-helpers >`.
83
100
84
- .. _helpers-loading-from-non-standard-locations :
101
+ .. _helpers-loading-from-specified-namespace :
85
102
86
- Loading from Non-standard Locations
87
- ===================================
103
+ Loading from Specified Namespace
104
+ ================================
88
105
89
106
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
+
92
109
You would prefix the name of the Helper with the namespace that it can be located
93
110
in. Within that namespaced directory, the loader expects it to live within a
94
111
sub-directory named **Helpers **. An example will help understand this.
0 commit comments