The configuration of the thinkphp is very flexible and can be customized for loading. I've probably looked at it, and there are a few places that will load the configuration file for later reading
/** * Get and set configuration parameters support Batch definition * * @param string|array $name * Config variable * @param mixed $value * Config value * @return mixed */function C ($name = null, $value = null) {Static $_config = array (); Get all if (empty ($name)) {if (! empty ($value) && $array = S (' c_ '. $value) without parameters) { $_config = Array_merge ($_config, Array_change_key_case ($array)); } return $_config; }//Priority execution set GET or assign if (is_string ($name)) {if (! Strpos ($name, '. ')) {$name = Strtolower ($name); if (Is_null ($value)) return isset ($_config [$name])? $_config [$name]: null; $_config [$name] = $value; Return }//Two-D array set up and get support $name = explode ('. ', $name); $name [0] = strtolower ($name [0]); if (Is_null ($value)) return isset ($_config [$name [0]] [$name [1]])? $_config [$name [0]] [$name [1]]: null; $_config [$name [0] [$name [1]] = $value; Return }//Bulk Set if (Is_array ($name)) {$_config = Array_merge ($_config, Array_change_key_case ($name)); if (! empty ($value)) {//Save config Value S (' c_ '. $value, $_config); } return; } return null; Avoid illegal parameters}
C () function at run time, the configuration file will be loaded into the C () function, as long as necessary to extract it, and can temporarily increase their C function
1.think.class.php Buildapp method, load public config file conf/convention.php, cache into C method
Load Core Convention configuration file Think.class.php line 60th C (include Think_path. ' Conf/convention.php '); if (Isset ($mode [' config '])) {//Load mode config file C (Is_array ($mode [' config '])? $mode [' config ']:include $mode [' config ']); }
2. Loading the project's config.php file
Load the project configuration file Think.class.php line 66th if (Is_file (Conf_path. ' config.php ') C (include Conf_path. ') Config.php ');
3. Load the system tag profile thinkphp/conf/tags.php file, C (' extends ');
Load mode system behavior defines if (C (' app_tags_on ')) { if (isset ($mode [' extends ')]) { C (' extends ', Is_array ($mode [' Extends '])? $mode [' Extends ']:include $mode [' extends ']); } else{//default load system behavior extension definition C (' extends ', include Think_path. ' Conf/tags.php '); } }
4. Load the application tag configuration app/conf/tags.php C (' extends ');
Load app behavior Definition if (isset ($mode [' tags '])) { C (' tags ', is_array ($mode [' tags '])? $mode [' Tags ']:include $mode [' tags ']); ElseIf (Is_file (Conf_path. Tags.php ') { //default load project configuration directory of tags file definition C (' tags ', include Conf_path. ') Tags.php '); }
5. If it is debug mode, load thinkphp/conf/debug.php, and apply state debug file
if (app_debug) { //debug mode loads the system default profile C (include Think_path. ' Conf/debug.php '); Read the application state of debug mode $status = C (' app_status '); Load the corresponding project configuration file if (Is_file (Conf_path. $status. php ') //Allow the project to add Development mode configuration definition C (include Conf_path. $status. php '); } else{ //Deployment mode generates compiled files build_runtime_cache ($compile); }
6.app:init Call function.php load_ext_file function to load custom configuration file
In the Load_ext_file () function in function.php
/** * Load Dynamic extension file * @return void */function load_ext_file () { //Load Custom external file if (C (' Load_ext_file ')) { $files = explode (', ', C (' load_ext_file ')); foreach ($files as $file) { $file = Common_path. $file. PHP '; if (Is_file ($file)) include $file; } } Load the custom dynamic profile if (C (' Load_ext_config ')) { $configs = C (' Load_ext_config '); if (is_string ($configs)) $configs = explode (', ', $configs); foreach ($configs as $key = = $config) { $file = Conf_path. $config. PHP '; if (Is_file ($file)) { is_numeric ($key)? C (include $file): C ($key, include $file);}}}
This article is from the "Deanne Lei" blog, please be sure to keep this source http://a3147972.blog.51cto.com/2366547/1413056