Jump to content

Recommended Posts

Configuration
Introduction

The main installation configuration parameters are stored in the following locations:

Type     Location
Global     includes/ClicShopping/Conf/global.php
Shop     includes/ClicShopping/Sites/Shop/site_conf.php
Shop     includes/ClicShopping/Sites/ClicShoppingAdmin/site_conf.php

The global configuration file and all site configuration files are automatically loaded into their own groups when the framework is initialized. The global configuration file is loaded into a 'global' group, and the site configuration files are loaded into their own Site group (eg, 'ClicShoppingAdmin', and 'Shop').

Reading a configuration value is first attempted at the Site level, and if the configuration key does not exist, the global value is returned. A Site level configuration parameter has priority over a global level parameter if a global level configuration parameter is also defined.

Custom Configuration Files

It's possible to create custom configuration files that have priority over the values from the core configuration files. Custom configuration files can be stored in the following locations:

Type     Location
Global     includes/ClicShopping/Custom/Conf/global.php
Per-Site     includes/ClicShopping/Custom/Sites/SITE/site_conf.php
Configuration File Format

The format of the configuration parameters are stored in a "ini" style format in a PHP file that is assigned to a $ini PHP variable. This style of configuration was chosen over a plain text .ini file to prevent configuration parameters being read in cases of the configuration files being publicly accessible through the web server.

An example format for the global configuration file is:

<?php
$ini = <<<EOD
db_server = "localhost"
db_server_username = "dbuser"
db_server_password = "dbpass"
db_database = "my_db_name"
db_table_prefix = "clic_"
store_sessions = "MySQL"
time_zone = "Europe/Berlin"
EOD;

An example of a Site configuration file is:

<?php
$ini = <<<EOD
dir_root = "/www/html/"
http_server = "https://demo.shop"
http_path = "/"
http_images_path = "images/"
http_cookie_domain = ".clicshopping.shop"
http_cookie_path = "/"
EOD;

External Configuration Files

External configuration files can be loaded using the following code:

use ClicShopping\OM\CLICSHOPPING;
CLICSHOPPING::loadConfigFile($path_of_file, 'ext_group');

This would load the configuration parameters of $path_of_file to the 'ext_group' configuration group.

It is important that the ini format is stored as a string to the $ini PHP variable otherwise the configuration parameters can not be parsed.

Retrieving Configuration Parameters

Configuration parameters can be retrieved using CLICSHOPPING::getConfig():

use ClicShopping\OM\CLICSHOPPING;
$value = CLICSHOPPING::getConfig('cfg_name');

In this example, the cfg_name configuration parameter from the current Site group is returned. If the current Site group does not contain the configuration parameter, the global group value is returned.

It's possible to define which group the configuration parameter should be loaded from by defining the group name:

use ClicShopping\OM\CLICSHOPPING;
$value = CLICSHOPPING::getConfig('cfg_name', 'ext_group');

This would load the cfg_name configuration parameter from the ext_group group.

The following can be used to first see if a configuration parameter exists:

use ClicShopping\OM\CLICSHOPPING;

if (CLICSHOPPING::configExists('cfg_name')) {
    ....
}

This will check if cfg_name exists in the current Site group or the global group.

Checking to see if a configuration parameter exists in a specific group is performed as follows:

use ClicShopping\OM\CLICSHOPPING;

if (CLICSHOPPING::configExists('cfg_name', 'ext_group')) {
    ....
}

Please note that if the configuration parameter does not exist in the specified group, a check is also performed in the global group.

Setting Configuration Parameters

Runtime configuration parameters can be set as follows:

use ClicShopping\OM\CLICSHOPPING;

$value = true;

CLICSHOPPING::setConfig('is_true', $value, 'ext_group');

If no group is specified in the third parameter, the configuration parameter would be set in the global group.

This function does not save the configuration parameter to the configuration file - it only sets a runtime configuration parameter value.

 

Link to post
Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use