@@ -64,20 +64,51 @@ The value is the location to the directory the classes can be found in.
64
64
65
65
php spark namespaces
66
66
67
+ .. _autoloader-application-namespace :
68
+
69
+ Application Namespace
70
+ =====================
71
+
67
72
By default, the application directory is namespace to the ``App `` namespace. You must namespace the controllers,
68
73
libraries, or models in the application directory, and they will be found under the ``App `` namespace.
69
74
75
+ Config Namespace
76
+ ----------------
77
+
78
+ Config files are namespaced in the ``Config `` namespace, not in ``App\Config `` as you might
79
+ expect. This allows the core system files to always be able to locate them, even when the application
80
+ namespace has changed.
81
+
82
+ Changing App Namespace
83
+ ----------------------
84
+
70
85
You may change this namespace by editing the **app/Config/Constants.php ** file and setting the
71
86
new namespace value under the ``APP_NAMESPACE `` setting:
72
87
73
88
.. literalinclude :: autoloader/002.php
74
89
:lines: 2-
75
90
76
- You will need to modify any existing files that are referencing the current namespace.
91
+ And if you use Composer autoloader, you also need to change the ``App `` namespace
92
+ in your **composer.json **, and run ``composer dump-autoload ``.
77
93
78
- .. important :: Config files are namespaced in the ``Config`` namespace, not in ``App\Config`` as you might
79
- expect. This allows the core system files to always be able to locate them, even when the application
80
- namespace has changed.
94
+ .. code-block :: text
95
+
96
+ {
97
+ ...
98
+ "autoload": {
99
+ "psr-4": {
100
+ "App\\": "app/" <-- Change
101
+ },
102
+ ...
103
+ },
104
+ ...
105
+ }
106
+
107
+ .. note :: Since v4.5.0 appstarter, the ``App\\`` namespace has been added to
108
+ **composer.json **'s ``autoload.psr-4 ``. If your **composer.json ** does not
109
+ have it, adding it may improve your app's autoloading performance.
110
+
111
+ You will need to modify any existing files that are referencing the current namespace.
81
112
82
113
********
83
114
Classmap
@@ -109,28 +140,3 @@ autoloader will be the first one to get a chance to locate the file.
109
140
110
141
.. note :: Prior to v4.5.0, if the same namespace was defined in both CodeIgniter and Composer, CodeIgniter's autoloader was
111
142
the first one to get a chance to locate the file.
112
-
113
- .. _autoloader-composer-support-improve-performance :
114
-
115
- Improve Performance
116
- ===================
117
-
118
- .. versionadded :: 4.5.0
119
-
120
- When you use Composer, you may improve the performance of autoloading with
121
- Composer's classmap dump.
122
-
123
- Add your ``App `` namespace in your **composer.json **, and run ``composer dump-autoload ``.
124
-
125
- .. code-block :: text
126
-
127
- {
128
- ...
129
- "autoload": {
130
- "psr-4": {
131
- "App\\": "app/",
132
- },
133
- ...
134
- },
135
- ...
136
- }
0 commit comments