Development - Configuration Files
All framework configuration files are PHP files. A configuration file
contains PHP code returning a named array of parameters as shown below:
<?php
return array(
// main settings
'param1' => 'value1',
'param2' => 'value2',
// additional settings
'param3' => array(
'param3_1' => 'value3_1',
'param3_2' => 'value3_2',
'param3_3' => 'value3_3',
),
...
);
Application configuration files
The application-related configuration files must be placed in protected/config/
subdirectory
inside the application directory. Changing the location or the name of a configuration file is not allowed.
File main.php
File main.php
is the main configuration file of the application. It contains the application name,
current version number, default template, controller, action and other parameters.
Example of the main.php
file for Login System application:
<?php
return array(
// application data
'name'=>'Login System',
'version'=>'0.0.1',
// installation settings
'installationKey' => 'YOUR_INSTALLATION_KEY',
// password keys settings (for database passwords only - don't change it)
// md5, sha1, sha256, whirlpool, etc.
'password' => array(
'encryption' => true,
'encryptAlgorithm' => 'sha256',
'encryptSalt' => true,
'hashKey' => 'YOUR_HASH_PASSWORD_KEY',
),
// default email settings
'email' => array(
'mailer' => 'smtpMailer', /* phpMail | phpMailer | smtpMailer */
'from' => 'info@email.me',
'fromName' => '', /* John Smith */
'isHtml' => true,
'smtp' => array(
'auth' => true, /* true or false */
'secure' => 'ssl', /* 'ssl', 'tls' or '' */
'host' => 'smtp.gmail.com',
'port' => '465',
'username' => '',
'password' => '',
),
),
// validation
'validation' => array(
'csrf' => true
'bruteforce' => array('enable' => true, 'badLogins' => 5, 'redirectDelay' => 3),
),
// session settings
'session' => array(
'customStorage' => false, /* true value means use a custom storage (database), false - standard storage */
'cacheLimiter' => '', /* to prevent 'Web Page expired' message for POST request use "private,must-revalidate" */
'lifetime' => 24, /* session timeout in minutes, default: 24 min = 1440 sec */
),
// cookies settings
'cookies' => array(
'domain' => '',
'path' => '/'
),
// cache settings
'cache' => array(
'enable' => false,
'lifetime' => 20, /* in minutes */
'path' => 'protected/tmp/cache/'
),
// RSS Feed settings
'rss' => array(
'path' => 'feeds/'
),
// datetime settings
'defaultTimeZone' => 'UTC',
// application settings
'defaultTemplate' => 'default',
'defaultController' => 'Index',
'defaultAction' => 'index',
// application components
'components' => array(
'Bootstrap' => array('enable' => true, 'class' => 'Bootstrap'),
// other components...
),
// application helpers
'helpers' => array(
//'helper' => array('enable' => true, 'class' => 'Helper'),
// other helpers...
),
// application modules
'modules' => array(
'setup' => array('enable' => true, 'removable' => false),
// other modules...
),
// url manager
'urlManager' => array(
'urlFormat' => 'shortPath', /* get | path | shortPath */
'rules' => array(
//'controller/action/value1/value2' => 'controller/action/param1/value1/param2/value2',
),
),
);
Below the list of all parameters that can be used in file main.php
:
- name: application name, required parameter
- version: application version number (optional parameter)
- installationKey: application installation key (used to identify specific installation)
- password.encryption: specifies whether to use password encryption or not
- password.encryptAlgorithm: encryption algorithm
- password.encryptSalt: specifies whether to use "salt" for passwords encryption
- password.hashKey: password hash key (used to encrypt passwords in database)
- email.mailer: specifies mailer type
- email.from: specifies email address used as "from" email
- email.fromName: specifies email sender name used as "fromName <from>"
- email.isHtml: specifies whether to send HTML code in emails or not
- email.smtp: defines SMTP connection parameters
- validation.csrf: specifies whether to allow CSRF validation
- validation.bruteforce: specifies whether to allow bruteforce validation
- session.customStorage: defines whether to use a custom storage
- session.cacheLimiter: defines cache limiter value for session
- cookies.domain: defines domain that the cookie is available to
- cookies.path: defines path on the server where the cookie will be available on
- cache.enable: enables cache
- cache.lifetime: defines a lifetime of cache in minutes
- cache.path: defines a path to cache files
- defaultTimeZone: defines default timezone for application
- defaultTemplate: specifies default template for application
- defaultController: specifies default controller
- defaultAction: specifies default action
- components: specifies allowed application components
- modules: specifies allowed application modules
- urlManager: defines rules for URL routing
File db.php
File db.php
contains database connection parameters.
Example of the db.php
file for Login System application:
<?php
return array(
// database settings
'db' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'mvc',
'username' => 'root',
'password' => '',
'prefix' => 'apcmf_',
'charset' => 'uft8',
'schema' => 'public'
),
);
Below the list of all parameters that can be used in file db.php
:
- db.driver: the type of database: mysql, mssql, etc.
- db.host: database host
- db.database: database name
- db.user: database user
- db.password: database user password
- db.prefix: prefix for database tables (optional parameter)
- db.charset: charset for database tables (optional parameter, default - uft8)
- db.schema: schema for database (optional parameter)
Examples of using configuration in application code
Setting up mailer configuration:
CMailer::config(array('mailer'=>CConfig::get('email.mailer')));
Setting up db connection:
parent::__construct(
CConfig::get('db.driver').':host='.CConfig::get('db.host').';dbname='.CConfig::get('db.database'),
CConfig::get('db.username'),
CConfig::get('db.password')
);
Module Files
ApPHP framework allows to export while installation module configuration files in config
directory. This feature allows application to merge them and use like a one configuration file.
To read more info click here.