You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: user_guide_src/source/general/configuration.rst
+26-10Lines changed: 26 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,19 +18,24 @@ the application configuration files in the **app/Config** folder.
18
18
Working with Configuration Files
19
19
********************************
20
20
21
+
Getting a Config Object
22
+
=======================
23
+
21
24
You can access configuration files for your classes in several different ways.
22
25
23
-
- By using the ``new`` keyword to create an instance:
26
+
new keyword
27
+
-----------
24
28
25
-
.. literalinclude:: configuration/001.php
29
+
By using the ``new`` keyword to create an instance:
26
30
27
-
- By using the ``config()`` function:
31
+
.. literalinclude:: configuration/001.php
28
32
29
-
.. literalinclude:: configuration/002.php
33
+
config()
34
+
--------
30
35
31
-
All configuration object properties are public, so you access the settings like any other property:
36
+
By using the ``config()`` function:
32
37
33
-
.. literalinclude:: configuration/003.php
38
+
.. literalinclude:: configuration/002.php
34
39
35
40
If no namespace is provided, it will look for the file in all defined namespaces
36
41
as well as **app/Config/**.
@@ -39,10 +44,16 @@ All of the configuration files that ship with CodeIgniter are namespaced with
39
44
``Config``. Using this namespace in your application will provide the best
40
45
performance since it knows exactly where to find the files.
41
46
42
-
You can put configuration files in any folder you want by using a different namespace.
43
-
This allows you to put configuration files on the production server in a folder
44
-
that is not web-accessible while keeping it under **/app** for easy access
45
-
during development.
47
+
.. note:: ``config()`` finds the file in **app/Config/** when there is a class with the same shortname,
48
+
even if you specify a fully qualified class name like ``config(\Acme\Blog\Config\Blog::class)``.
49
+
This is because ``config()`` is a wrapper for the ``Factories`` class which uses ``preferApp`` by default. See :ref:`factories-loading-class` for more information.
50
+
51
+
Getting a Config Property
52
+
=========================
53
+
54
+
All configuration object properties are public, so you access the settings like any other property:
55
+
56
+
.. literalinclude:: configuration/003.php
46
57
47
58
Creating Configuration Files
48
59
****************************
@@ -52,6 +63,11 @@ The default file location (recommended for most cases) is **app/Config**.
52
63
The class should use the appropriate namespace, and it should extend
53
64
``CodeIgniter\Config\BaseConfig`` to ensure that it can receive environment-specific settings.
54
65
66
+
You can put configuration files in any folder you want by using a different namespace.
67
+
This allows you to put configuration files on the production server in a folder
68
+
that is not web-accessible while keeping it under **/app** for easy access
69
+
during development.
70
+
55
71
Define the class and fill it with public properties that represent your settings:
0 commit comments