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: docs/4.x/config/README.md
+72-2Lines changed: 72 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -92,7 +92,7 @@ Each setting accepts specific [types and values](#types-and-values) (like an int
92
92
Craft takes the first discovered value, in this order:
93
93
94
94
0.**Environment Overrides:** For general and database settings, Craft looks for special [environment variables](#environment-overrides) and [PHP constants](#php-constants).
95
-
1.**Config Files:** Craft [evaluates and merges](#multi-environment-configs) PHP config files.
95
+
1.**Config Files:** Craft evaluates and merges[multi-environment](#multi-environment-configs) and [application type](#application-types) PHP config files.
96
96
2.**Defaults:** Every option has a default value, even if it’s `null`. You can find these defaults in the documentation for each setting.
Each option becomes a method call, accepting the same values that you would provide in a config map. The modified configuration object is returned to allow chaining.
123
123
124
124
::: warning
125
-
Fluent config is currently only available for _general_ and _database_ settings, and unsupported in plugins. When in doubt, use a config map!
125
+
Fluent config is currently only available for _general_ and _database_ settings, and unsupported in plugins, [custom](#custom-settings) config files, and [application config](#application-configuration). When in doubt, use a config map!
126
+
:::
127
+
128
+
Config files can also return a closure that accepts a single `$config` argument and returns a config object. <Sincever="4.11.0"feature="Closures in config files" />
129
+
130
+
```php
131
+
// config/general.php
132
+
133
+
use craft\config\GeneralConfig;
134
+
135
+
return function(GeneralConfig $config) {
136
+
return $config
137
+
->aliases([
138
+
'@webroot' => dirname(__DIR__) . '/web',
139
+
])
140
+
// ...
141
+
;
142
+
};
143
+
```
144
+
145
+
Craft will always pass an instance of <craft5:craft\config\GeneralConfig> or <craft5:craft\config\DbConfig> to a closure in the primary general or database config files, respectively—but [application type-specific files](#application-types) should accept whatever the _primary_ file returns:
There is no equivalent to `GeneralConfig` and `DbConfig` for [application](#application-configuration). If you return an array from the primary file, there is limited value in using a closure in an application type-specific file.
165
+
166
+
::: tip
167
+
The `GeneralConfig` class has a special `addAlias()` method that allows you to merge additional aliases, when using closures _and_ fluent config.
Craft has two primary application types—_web_ and _console_. Web requests are typically initiated by an HTTP server via `index.php`; console requests are initiated from the `craft` executable, on the command line.
173
+
174
+
You can provide configuration that targets a specific application type by creating additional general, database, application, or custom configuration files with the appropriate suffix:
175
+
176
+
<divclass="croker-table">
177
+
178
+
Category | File | Application Type
179
+
--- | --- | ---
180
+
[General](#general) | `general.php` | All
181
+
| `general.web.php` | Web only
182
+
| `general.console.php` | Console only
183
+
[Database](#database) | `db.php` | All
184
+
| `db.web.php` | Web only
185
+
| `db.console.php` | Console only
186
+
[Application](#application-configuration) | `app.php` | All
187
+
| `app.web.php` | Web only
188
+
| `app.console.php` | Console only
189
+
190
+
</div>
191
+
192
+
The primary config file is always evaluated, but only one of the `web` or `console` files are merged on top of it, when present.
193
+
194
+
::: tip
195
+
See the previous section for some examples of how to combine application type-specific configuration and config styles.
There is no equivalent to `GeneralConfig` and `DbConfig` for [application](#application-configuration) or [custom](#custom-settings) config files. If you return an array from the primary file, there is limited value in using a closure in an application type-specific file.
169
+
There is no equivalent to `GeneralConfig` and `DbConfig` for [application](#application-configuration). If you return an array from the primary file, there is limited value in using a closure in an application type-specific file.
170
170
171
171
::: tip
172
172
The `GeneralConfig` class has a special `addAlias()` method that allows you to merge additional aliases, when using closures _and_ fluent config.
@@ -176,7 +176,7 @@ The `GeneralConfig` class has a special `addAlias()` method that allows you to m
176
176
177
177
Craft has two primary application types—_web_ and _console_. Web requests are typically initiated by an HTTP server via `index.php`; console requests are initiated from the `craft` executable, on the command line.
178
178
179
-
You can provide configuration that targets a specific application type by creating additional general, database, application, or custom configuration files with the appropriate suffix:
179
+
You can provide configuration that targets a specific application type by creating additional general, database, or application configuration files with the appropriate suffix:
180
180
181
181
<divclass="croker-table">
182
182
@@ -191,16 +191,13 @@ Category | File | Application Type
191
191
[Application](#application-configuration) | `app.php` | All
192
192
| `app.web.php` | Web only
193
193
| `app.console.php` | Console only
194
-
[Custom](#custom-settings) | `custom.php` | All
195
-
| `custom.web.php` | Web only
196
-
| `custom.console.php` | Console only
197
194
198
195
</div>
199
196
200
197
The primary config file is always evaluated, but only one of the `web` or `console` files are merged on top of it, when present.
201
198
202
199
::: tip
203
-
See the previous section for some examples of how to combine application type-specific configuration and config styles. General and database config files support [fluent](#style) config, but application and custom config files do not.
200
+
See the previous section for some examples of how to combine application type-specific configuration and config styles.
0 commit comments