Manual â
Configuration â
Default configurations are categorized as:
app configuration
env-based configuration
custom configuration
Those files are located under
config/.
đĄ Usage
Get configuration value from config file name
Config::getConfig(string $key, string $configname = "environment"): mixedkey
â A dot notation (e.g: data.name.last)
configname (optional)
â Your configuration file name without extension
Check a configuration key if has value from config file name
Config::hasConfig(string $key, string $configname = "environment"): boolkey
â A dot notation (e.g: data.name.last)
configname (optional)
â Your configuration file name without extension
Get all configurations from config file name
Config::allConfig(string $configname = "environment"): mixedconfigname (optional)
â Your configuration file name without extension
âšī¸ NOTE
configname default value is "environment". If you don't supply configname parameter, it gets environment-based configuration and will give result following the environment already defined in env (for example: development or staging or production)
App configuration â
It's located in config/app.php. You can add, change the configuration or create your own config file for your need
| Config | Type | Description |
|---|---|---|
lctime | String | Local region information. |
timezone | String | Your app time zone. List can be seen here. |
supportHtaccess | Boolean | htaccess support in your server. Setting true or false whether your server doesn't support htaccess or you don't use htaccess. mod_rewrite support is explained in Routing page. |
connectionheader | String | Controls whether the network connection stays open after the current transaction finishes. The detail is explained in this page. |
errorformat | String | Output format for error as JSON, XML or HTML. The detail is explained in this page |
Example:
Config::getConfig("settings.timezone", "app"); // output: Asia/JakartaEnvironment-based configuration â
Snappy supports environment-based configuration, allowing you to define different settings for development, testing, and production. This helps your application automatically load the appropriate configuration based on the current environment.
Environment-based configuration is taking from config/environment.php
| Config | Description |
|---|---|
db | database connection configuration. |
view | location of your template files. |
email | your email configuration. |
assets | location of your assets files such as images, videos etc. |
showerror | to show/hide error message in the response body. |
logerror | to log error message in a file under log/ directory. |
Example:
Config::getConfig("showerror"); // trueCustom configuration â
Create a file under config/ directory containing an associative array. You may also define nested associative arrays if needed. The file name will be the config name.
Example:
// config/myconfig.php
return [
"list" => [
"john" => "doe",
"jane" => "dane",
"anotherconfig" => [
"subconfig" => 123
],
],
"name" => "John Doe"
];
// accessing custom config
Config::getConfig("list.john","myconfig"); //output: doe
Config::getConfig("list.anotherconfig.subconfig","myconfig"); //output: 123
Config::getConfig("name","myconfig"); //output: John Doe