The reading and C methods configured in thinkPHP are described in detail, and thinkphp reading is described in detail.
This article describes the read and C methods configured in thinkPHP. We will share this with you for your reference. The details are as follows:
1. Public configuration of the project
Conf/config. php
The content is as follows:
<? Php/*** public project configuration * @ package * @ author **/return array ('Load _ EXT_CONFIG '=> 'db, info, email, safe, upfile, cache, route, app, alipay, sms, platform, store, pay', 'app _ AUTOLOAD_PATH '=> '@. ORG ', 'output _ encode' => true, // PAGE compression OUTPUT 'page _ num' => 15, /* Cookie configuration */'cookie _ path' => '/', // cookie path 'cookie _ prefix' => '', // avoid Cookie prefix conflict/* define template tag */'tmpl _ L_DELIM '=>' {sh :', // The template engine standard tag starts to mark 'tmpl _ R_DELIM '=>'} ', // The template engine standard tag End tag 'tmpl _ CACHE_ON '=> false, // disable the template cache 'default _ group' => 'home', // DEFAULT access GROUP, set the default entry 'app _ GROUP_LIST '=> 'agent, Home, System, User, Store, Wap, Mall, opener', // set the project group, multiple groups are separated by commas, for example, 'home, admin' 'public _ resourse' => '. /Public/', 'url _ 404_REDIRECT' => '. /Tpl/404.html ',);?>
'Load _ ext_config' => 'db, info, email, safe, upfile, cache, route, app, alipay, sms, platform, store, pay' determines the additional configurations to be loaded. These configurations can be read using the C () method and are globally valid.
2. If the module group is enabled, you can define the configuration file for each group separately. The group configuration file is located:
Project configuration directory/group name/config. php
'App _ GROUP_LIST '=> 'home, admin', // set 'default _ group' => 'home' for the Project GROUP, // DEFAULT GROUP
Now we have defined the Home and Admin groups. We can define the group configuration file as follows:
Conf/Home/config.phpConf/Admin/config.php
The configuration file of each group is only valid for the current group. The Definition Format of the group configuration is the same as that of the project configuration.
Note: The group name is case sensitive and must be consistent with the defined group name.
3. Read Configuration
After defining the configuration file, you can use the C method provided by the system (if you think it is strange, you can use the Config word to help remember) to read the existing configuration
C ('parameter name') // obtain the set parameter value
For example, C ('app _ status') can read the setting value of the system's debugging mode. Similarly, because the configuration parameters are case-insensitive, C ('app _ status ') is equivalent, but it is recommended to use the standard in upper case.
If no APP_STATUS is set, NULL is returned.
The C method can also be used to read two-dimensional configurations.
C ('user _ CONFIG. USER_TYPE ') // obtain the USER type settings in USER configuration
Method C reads the global configuration and the configuration of the current module.
If no parameter exists, all valid configurations are read.
If the same configuration name exists, the previous value will be overwritten.
For example:
'Html _ CACHE_TIME '=> 60, // static cache validity period (seconds) 'html _ CACHE_TIME' => 80,
The final result is 80.
Load order according to the parameter LOAD_EXT_CONFIG
'LOAD_EXT_CONFIG' => 'db,info,email,safe,upfile,cache,route,app,alipay,sms,platform,store,pay'
For example, if the HTML_CACHE_TIME parameter in info is 60 but not in other configurations, the parameter is read as 60.
If the value of HTML_CACHE_TIME in the database is 50, the value is still 60. Because info is read later, the HTML_CACHE_TIME In the db is overwritten.
Attaches the C method source code
/*** You can obtain and set configuration parameters in batches. * @ param string | array $ name configuration variable * @ param mixed $ value configuration value * @ return mixed */function C ($ name = null, $ value = null) {static $ _ config = array (); // obtain all if (empty ($ name) {if (! Empty ($ value) & $ array = cache ('C _'. $ value) {$ _ config = array_merge ($ _ config, array_change_key_case ($ array);} return $ _ config ;} // preferentially execute the settings to get or assign values 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;} // supports $ 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;} // set if (is_array ($ name) in batches )) {$ _ config = array_merge ($ _ config, array_change_key_case ($ name); if (! Empty ($ value) {// Save the configuration value cache ('C _ '. $ value, $ _ config) ;}return ;} return null; // avoid invalid parameters}