There is no doubt that the C method is a common method for manipulating configuration items in thinkphp.
The C method is the thinkphp used to set up, get, and save configuration parameters, with a high frequency.
Understanding the C method requires first understanding the configuration of the next thinkphp, because all operations of the C method are related to configuration. The thinkphp configuration file is defined in PHP array format.
Due to the use of the function overload design, so the use of more, we come to one by one instructions.
Set parameters:
C (' db_name ', ' thinkphp ');
C (' db_name ', ' thinkphp ');
Because the configuration parameters are not case-sensitive, so the above 2 settings on this side of the expression meaning is the same, set in the configuration file, the value of ' db_name ' is ' thinkphp '.
But it is generally configured in uppercase, and the last configured value overrides the previous setting or the value that exists in the file.
In this configuration file, it is best to configure no more than level two
C (' USER. USER_ID ', 8);
To set multiple variables, you can set them in batches, which can be implemented as follows:
$config [' id '] = 1;
$config [' name '] = ' realname ';
C ($config);
The function of the above method is equivalent to = "
C (' ID ', 1);
C (' NAME ', 1);
Read parameters:
$id = C (' id ');
$config = C ();
If you do not pass in a parameter, you are reading all of the configuration file contents.
Save Settings:
Version 3.1 adds a feature that permanently saves settings parameters only for batch assignments, such as:
$config [' user_id '] = 1; $config [' user_type '] = 1; C ($config, ' name ');
After the config parameter is set in bulk, it is saved to the cache file (or other configured cache mode), along with all current configuration parameters.
After saving, if you want to retrieve the saved parameters, you can use C (', ' name ') to read the configuration file. Where name is the identity of the cache that was used to save the parameter earlier, it must be consistent to retrieve the saved parameters correctly. The retrieved parameters are merged with the current configuration parameters and do not need to be merged manually.
Reprint Address: http://www.thinkphp.cn/simple/functions_c.html
thinkphp Function: C method