Skip to content

Commit 9a9a5ed

Browse files
committed
docs: update description for app namespace
1 parent b52f770 commit 9a9a5ed

File tree

2 files changed

+38
-32
lines changed

2 files changed

+38
-32
lines changed

user_guide_src/source/changelogs/v4.5.0.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ Helpers and Functions
116116
Others
117117
======
118118

119-
- **Autoloader:** Autoloading performance when using Composer has been improved;
120-
changing the ``autoload.psr4`` setting in **composer.json** may also improve
121-
the performance of your app. See :ref:`autoloader-composer-support-improve-performance`.
119+
- **Autoloader:** Autoloading performance when using Composer has been improved.
120+
Adding the ``App`` namespace in the ``autoload.psr4`` setting in **composer.json**
121+
may also improve the performance of your app. See :ref:`autoloader-application-namespace`.
122122

123123
Message Changes
124124
***************

user_guide_src/source/concepts/autoloader.rst

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,51 @@ The value is the location to the directory the classes can be found in.
6464
6565
php spark namespaces
6666
67+
.. _autoloader-application-namespace:
68+
69+
Application Namespace
70+
=====================
71+
6772
By default, the application directory is namespace to the ``App`` namespace. You must namespace the controllers,
6873
libraries, or models in the application directory, and they will be found under the ``App`` namespace.
6974

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+
7085
You may change this namespace by editing the **app/Config/Constants.php** file and setting the
7186
new namespace value under the ``APP_NAMESPACE`` setting:
7287

7388
.. literalinclude:: autoloader/002.php
7489
:lines: 2-
7590

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``.
7793

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.
81112

82113
********
83114
Classmap
@@ -109,28 +140,3 @@ autoloader will be the first one to get a chance to locate the file.
109140

110141
.. note:: Prior to v4.5.0, if the same namespace was defined in both CodeIgniter and Composer, CodeIgniter's autoloader was
111142
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

Comments
 (0)