Skip to content

Commit f32eaa5

Browse files
authored
Merge pull request #7348 from kenjis/fix-docs-autoloader.rst
docs: fix out of dated description in autoloader.rst
2 parents d483d57 + 9ed4900 commit f32eaa5

File tree

4 files changed

+34
-13
lines changed

4 files changed

+34
-13
lines changed

user_guide_src/source/concepts/autoloader.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,26 @@ Namespaces
4747

4848
The recommended method for organizing your classes is to create one or more namespaces for your
4949
application's files. This is most important for any business-logic related classes, entity classes,
50-
etc. The ``psr4`` array in the configuration file allows you to map the namespace to the directory
50+
etc. The ``$psr4`` array in the configuration file allows you to map the namespace to the directory
5151
those classes can be found in:
5252

5353
.. literalinclude:: autoloader/001.php
5454

5555
The key of each row is the namespace itself. This does not need a trailing back slash.
56-
The value is the location to the directory the classes can be found in. They should
57-
have a trailing slash.
56+
The value is the location to the directory the classes can be found in.
5857

5958
.. note:: You can check the namespace configuration by ``spark namespaces`` command::
6059

6160
> php spark namespaces
6261

63-
By default, the application folder is namespace to the ``App`` namespace. While you are not forced to namespace the controllers,
64-
libraries, or models in the application directory, if you do, they will be found under the ``App`` namespace.
62+
By default, the application directory is namespace to the ``App`` namespace. You must namespace the controllers,
63+
libraries, or models in the application directory, and they will be found under the ``App`` namespace.
64+
6565
You may change this namespace by editing the **app/Config/Constants.php** file and setting the
6666
new namespace value under the ``APP_NAMESPACE`` setting:
6767

6868
.. literalinclude:: autoloader/002.php
69+
:lines: 2-
6970

7071
You will need to modify any existing files that are referencing the current namespace.
7172

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
<?php
22

3-
$psr4 = [
4-
'App' => APPPATH,
5-
'CodeIgniter' => SYSTEMPATH,
6-
];
3+
namespace Config;
4+
5+
use CodeIgniter\Config\AutoloadConfig;
6+
7+
class Autoload extends AutoloadConfig
8+
{
9+
// ...
10+
public $psr4 = [
11+
APP_NAMESPACE => APPPATH, // For custom app namespace
12+
'Config' => APPPATH . 'Config',
13+
];
14+
15+
// ...
16+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?php
22

3-
define('APP_NAMESPACE', 'App');
3+
defined('APP_NAMESPACE') || define('APP_NAMESPACE', 'App');
Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
<?php
22

3-
$classmap = [
4-
'Markdown' => APPPATH . 'third_party/markdown.php',
5-
];
3+
namespace Config;
4+
5+
use CodeIgniter\Config\AutoloadConfig;
6+
7+
class Autoload extends AutoloadConfig
8+
{
9+
// ...
10+
public $classmap = [
11+
'Markdown' => APPPATH . 'ThirdParty/markdown.php',
12+
];
13+
14+
// ...
15+
}

0 commit comments

Comments
 (0)