Skip to content

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

php
Config::getConfig(string $key, string $configname = "environment"): mixed

key

  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

php
Config::hasConfig(string $key, string $configname = "environment"): bool

key

  A dot notation (e.g: data.name.last)

configname (optional)

  Your configuration file name without extension

Get all configurations from config file name

php
Config::allConfig(string $configname = "environment"): mixed

configname (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

ConfigTypeDescription
lctimeStringLocal region information.
timezoneStringYour app time zone. List can be seen here.
supportHtaccessBooleanhtaccess 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.
connectionheaderStringControls whether the network connection stays open after the current transaction finishes.
The detail is explained in this page.
errorformatStringOutput format for error as JSON, XML or HTML.
The detail is explained in this page

Example:

php
Config::getConfig("settings.timezone", "app"); // output: Asia/Jakarta

Environment-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

ConfigDescription
dbdatabase connection configuration.
viewlocation of your template files.
emailyour email configuration.
assetslocation of your assets files such as images, videos etc.
showerrorto show/hide error message in the response body.
logerrorto log error message in a file under log/ directory.

Example:

php
Config::getConfig("showerror"); // true

Custom 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:

php
// 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