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 inprotected/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', // Directy CMF data 'directy_cmf_version' => '3.0.2', // 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', ), // Password restore settings 'restoreAdminPassword' => array( 'enable' => true, 'recoveryType' => 'direct' /* 'direct' - send new password directly, 'recovery' - send a link to recovery page */ ), // 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), ), // HTTP headers 'httpHeaders' => array( 'secure' => true, 'framework' => true ), // Exception handling // Define exceptions exceptions in application 'exceptionHandling' => array( 'enable' => true, 'level' => 'global' ), // Output compression 'compression' => array( 'gzip' => array('enable' => true), 'html' => array('enable' => false), 'css' => array('enable' => false, 'path' => 'assets/minified/css/', 'minify' => array('frontend'=>true, 'backend'=>false)), 'js' => array('enable' => false, 'path' => 'assets/minified/js/', 'minify' => array('frontend'=>true, 'backend'=>false)), ), // 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, 'type' => 'auto', /* 'auto' or 'manual' */ 'lifetime' => 20, /* in minutes */ 'path' => 'protected/tmp/cache/' ), // Logger settings 'log' => array( 'enable' => true, 'path' => 'protected/tmp/logs/', 'fileExtension' => 'php', 'dateFormat' => 'Y-m-d H:i:s', 'threshold' => 1, 'filePermissions' => 0644, 'lifetime' => 30 /* in days */ ), // RSS Feed settings 'rss' => array( 'path' => 'feeds/' ), // Datetime settings 'defaultTimeZone' => 'UTC', // Template default settings 'template' => array( 'default' => 'default' ), // Layout default settings 'layouts' => array( 'enable' => true, 'default' => 'default' ), // Default settings (optional, if defined - will be used as application default settings) 'defaultBackendDirectory' => 'backend', /* default backend directory - don't change after installation */ 'defaultErrorController' => 'Error', /* may be overridden by module settings */ 'defaultController' => 'Index', /* may be overridden by module settings */ 'defaultAction' => 'index', /* may be overridden by module settings */ // Application payment complete page (controller/action - may be overridden by module settings) 'paymentCompletePage' => '', // Core components loading 'coreComponentsLazyLoading' => true, // Application components 'components' => array( 'Bootstrap' => array('enable' => true, 'class' => 'Bootstrap'), // Other components... ), // Widget settings 'widgets' => array( 'paramKeysSensitive' => false ), // 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' => 'controllerName/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)
- restoreAdminPassword.enable: whether to enable restore admin password
- restoreAdminPassword.recoveryType: admin reatore password recovery type
- 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
- exceptionHandling.enable: specifies whether to exceptions handling
- exceptionHandling.level: exceptions handling level
- compression.gzip: gzip compression configuration
- compression.html: html compression configuration
- compression.css: css compression configuration
- compression.js: js compression configuration
- session.customStorage: defines whether to use a custom storage
- session.cacheLimiter: defines cache limiter value for session
- session.lifetime: defines session lifetime
- 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.data.enable: enables data cache
- cache.db.enable: enables db cache
- cache.db.type: defines a cache type
- cache.db.lifetime: defines a lifetime of cache in minutes
- cache.db.path: defines a path to cache files
- log: defines a logging configuration
- rss: defines RSS feed settings
- defaultTimeZone: defines default timezone for application
- template.default: specifies default template for application
- layouts.enable: specifies whether to allow layouts for application
- layouts.default: specifies default layout for application
- defaultErrorController: specifies default error controller
- defaultController: specifies default controller
- defaultAction: specifies default action
- paymentCompletePage: specifies application payment complete page
- coreComponentsLazyLoading: specifies core components lazy loading
- components: specifies allowed application components
- widgets: specifies widgets settings
- 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', 'socket' => '', 'host' => 'localhost', 'port' => '', 'database' => 'mvc', 'username' => 'root', 'password' => '', 'prefix' => 'apcmf_', 'charset' => 'utf8', '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.socket: socket (e.g /tmp/mysql.sock) - if defined db.host is ignored
- db.host: database host
- db.port: database port
- db.database: database name
- db.username: database username
- db.password: database user password
- db.prefix: prefix for database tables (optional parameter)
- db.charset: charset for database tables (optional parameter, default - utf8)
- 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 inconfig
directory. This feature allows application to merge them and use like a one configuration file.
To read more info click here.