Leafiny Documentation

Configuration

This section describes Leafiny configuration in global config file.

Global configuration file

Global configuration file is located in etc directory.

Copy the config file for your environment without sample extension:

  • /etc/config.default.php.sample
  • /etc/config.dev.php.sample
  • /etc/config.preprod.php.sample
  • + /etc/config.dev.php

Environment is set in Apache ENVIRONMENT variable. See installation section. If the variable does not exist default is used.

This PHP config file contains environment-specific variables, such as database connection data.

In default git configuration, this files are ignored. Update .gitignore file according to your deployment process.

How config variables work

Variables are defined by config array keys. They are accessible in the objects defined by the configuration path. Example:

$config = [
    // ...
    'block' => [ // Object Type
        'default' => [ // Identifier
            'baseline' => 'Hello World!' // Variable
        ]
    ]
    // ...
];

The baseline (variable) will be accessible in all block objects with getCustom method:

$this->getCustom('baseline');

The default identifier applies our custom variable on all block objects

The variable will be accessible everywhere with App::getConfig static method:

App::getConfig('block.default.baseline');

Avoid using this method except for variables outside objects (ex: app.languages)

$config = [
    // ...
    'block' => [
        'header' => [
            'baseline' => 'Hello World!', // Override block.default.baseline
            'intro'    => 'This is the intro', // New variable
        ]
    ]
    // ...
];

Here the variables will be only apply on block nammed header (the identifier). The block.default settings are merged and overrided with block.header settings for this object.

Other configuration files are located in each etc directory of the modules.

Configuration priority

Configuration priority

Application

Open global config file (ex: /etc/config.dev.php).

Find and set up app configuration settings:

'app' => [
    'secured_port'       => 443,
    'secured_protocol'   => 'https://',
    'unsecured_protocol' => 'http://',
    'twig_cache'         => 0,
    'twig_debug'         => 1,
    'config_cache'       => 0,
    'backend_key'        => 'leafiny',
    'languages'          => ['fr_FR', 'en_US'],
],

Expected settings:

  • secured_port: SSL secured port
  • secured_protocol: SSL secured protocol
  • unsecured_protocol: Unsecured protocol
  • twig_cache: enabled template cache (1 / 0)
  • twig_debug: allow to debug variable in a twig template: {{ dump(var) }} (1 / 0)
  • config_cache: enabled configuration cache (1 / 0)
  • backend_key: the url key for admin access (/admin/{backend_key})
  • languages: available languages

When config cache is enabled, all updates in configuration files will not be available until cache refresh (var/cache/config). You should turn it off during development.

When twig cache is enabled, all updates in templates files will not be available until cache refresh (var/cache/twig). You should turn it off during development.

Use a secure and unique backend key.

If the site is not multi-language, specify a single language. Ex: ['en_US'].

Page

Open global config file (ex: /etc/config.dev.php).

Find and set up default page configuration settings:

'page' => [
    'default' => [
        'is_secure'    => 1,
        'locale'       => 'en_US.utf8',
        'timezone'     => 'America/Chicago',
        'fpc'          => 1,
        'allow_params' => 1,
    ],
],

Expected settings:

  • is_secure: set page secure connection (1 / 0). Automatic redirection from http to https if active
  • locale: set PHP locale information (useful for localized PHP functions as strcoll, strtoupper or strftime)
  • timezone: set the default timezone used by all date/time functions
  • fpc: enabled Full Page Cache (see Leafiny_Fpc module)
  • allow_params: Allow to use query params in the URL (?foo=bar). If disabled, a 404 will be sent when params appear in the URL. We recommend to always activate it.

This settings (page.default) are available for all pages.

Database

Open global config file (ex: /etc/config.dev.php).

Find and set up MySQL configuration settings:

'model' => [
    'default' => [
        'db_host'       => 'localhost',
        'db_username'   => 'username',
        'db_password'   => 'password',
        'db_database'   => 'leafiny',
        'lc_time_names' => 'en_US',
    ],
],

This settings (model.default) are available for all models.

Expected settings:

  • db_host: database host
  • db_username: user name
  • db_password: user password
  • db_database: database name
  • db_port: database port
  • db_no_writing: disabled all write statement (INSERT, REPLACE, UPDATE, DELETE, ALTER, CREATE, DROP, RENAME, TRUNCATE)
  • lc_time_names: language used to display day and month names and abbreviations

Use multi-database connexion with specific model settings. Example:

'model' => [
    'analytics' => [
        'db_host'     => 'localhost',
        'db_username' => 'username',
        'db_password' => 'password',
        'db_database' => 'analytics',
    ],
],

Database connection will be different for model named analytics. The model.analytics settings override model.default settings for this object.

Default connection:

/* @var Core_Model $model */
$model = App::getObject('model');

$users = $model->getAdapter()->get('admin_user'); // SELECT * FROM leafiny.admin_user;

Analyctics connection:

/* @var Core_Model $model */
$model = App::getObject('model', 'analytics');

$views = $model->getAdapter()->get('page_view'); // SELECT * FROM analytics.page_view;

Session

Open global config file (ex: /etc/config.dev.php).

Find and set up session configuration settings:

'session' => [
    'default' => [
        'lifetime' => 86400,
        'samesite' => 'strict',
    ],
    'backend' => [
        'lifetime' => 86400,
    ],
],

Default session lifetime is set to 86400 seconds and can be overrided for admin. Cookie SameSite attribute is set to strict for frontend and admin. For third-party payment modules (with redirection to the banking platform) lax is recommanded.

Session scopes:

  • session.default: frontend and admin default settings
  • session.backend: admin specific settings
  • session.frontend: frontend specific settings

Expected settings:

  • lifetime: session time in seconds
  • samesite: SameSite attribute value
  • domain: cookie domain

Mail

Open global config file (ex: /etc/config.dev.php).

Find and set up mail configuration settings:

'mail' => [
    'default' => [
        'recipient_email' => 'contact@example.com',
        'sender_email'    => 'contact@example.com',
        'sender_name'     => 'Leafiny',
        'smtp_enabled'    => 0,
        'smtp_auth'       => 1,
        'smtp_secure'     => 'tls',
        'smtp_host'       => '',
        'smtp_port'       => 587,
        'smtp_username'   => '',
        'smtp_password'   => '',
    ]
]

This settings (mail.default) are available for all mails.

Expected settings:

  • recipient_email: the recipient address
  • sender_email: the sender address
  • sender_name: the sender name
  • reply_to: the reply address (optional)
  • content_type: the body content type (default: text/html)
  • charset: the mail charset (default: utf-8)
  • headers: custom headers for simple mail (optional)
  • send_disabled: disabled all communications
  • smtp_enabled: enabled advanced mail (1 / 0)
  • smtp_auth: whether to use SMTP authentication (1 / 0)
  • smtp_secure: set the encryption mechanism to use (ssl, tls)
  • smtp_host: set the hostname of the mail server
  • smtp_port: set the SMTP port number (ex: 587 for authenticated TLS)
  • smtp_username: username to use for SMTP authentication
  • smtp_password: password to use for SMTP authentication