This website uses Cookies to provide you with the best possible service. Please see our Privacy Policy for more information. Click the check box below to accept cookies. Then confirm with a click on "Save".  
Status: 2022-10-20

Configuration


Environment public/.env

MVC_ENV
In the public/ folder you will find an .env file. There the variable MVC_ENV is declared. This variable declares what Environment is valid for myMVC.
You can name the value as you like - But common values are: develop, test, production.
Make sure, that the corresponding environment config file does exist in your module
(Schema: /modules/{moduleName}/etc/config/{moduleName}/config/{environment}.php).

Example
If your Module is named Foo, and you set MVC_ENV=production,
then the config file /modules/Foo/etc/config/Foo/config/production.php has to exist.

# Environment
MVC_ENV=production

Custom .env variables
You are free to set up any key=value declarations you want in that public/.env file. Any key=value pair found in the file will be set by putenv() at start and you can access those variables via php's getenv() command.

Example

# custom
foo=bar

Check

// string(3) "bar"
var_dump(
    getenv('foo')
);

Config files, -places and reading order

The following locations for configurations exist and are read in succession in the appropriate order.

This also means that a later loaded configuration beats (overrides) an earlier loaded one.

  1. โ†“ myMVC config folder
    • /config/
    • Any *.php file in this directory will be included; Reading order is a-z
    • Coverage: globally - Configs placed here are valid to all modules and to all environments
    • By default, the following files are located here
      • _myMVC.php: This file contains basic settings that are necessary for operation. You should not edit this file. If you want to change settings, override values in your own module config. myMVC config variable names always begin with MVC_.
  2. โ†“ Module's config folder
    • /modules/{moduleName}/etc/config/
    • Any *.php file in this directory will be included; Reading order is a-z
    • Coverage: module globally - Configs placed here are valid to all environments of your module
    • By default, the following files are located here
      • _myMVC.php: further MVC configs. myMVC config variable names always begin with MVC_.
      • policy.php: see policy rules
  3. โค“ Module's environment config file
    • Schema: /modules/{moduleName}/etc/config/{moduleName}/config/{environment}.php
      • Example: If your module is named Foo and you have set MVC_ENV to 'develop', your environment config file has to be modules/Foo/etc/config/Foo/config/develop.php. Make sure it exists.
    • Coverage: module environment specific - The concrete environment config file is loaded appropiate to your environment of your module you have set in MVC_ENV

Access MVC_* config values

You can access MVC configurations via the \MVC\Config Class. For each variable there is an identical getter.

syntax

$mVar = \MVC\Config::get_{MVC_VARIABLE}();

example

$sMvcBasePath = \MVC\Config::get_MVC_BASE_PATH();

Alternativley you can access all MVC Configs via \MVC\Registry.

alternative

$sMvcBasePath = \MVC\Registry::get('MVC_BASE_PATH');

Access module config values

You can access module configuration array via the \MVC\Config Class.

example

$aModule = \MVC\Config::MODULE();

Alternativley you can access the module configuration array via \MVC\Registry.

alternative

$aModule = \MVC\Registry::get('MODULE');