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.
Setting parameters
C (' db_name ', ' thinkphp ');
The value for setting the db_name configuration parameter is thinkphp, because the configuration parameters are not case-sensitive, so the following is the same notation:
C (' db_name ', ' thinkphp ');
However, it is recommended that you maintain a uniform capitalization configuration definition specification.
All parameters of the project can be dynamically changed by this method before it takes effect, and the last set value overrides the definition in the previous setting or custom configuration, or you can add a new configuration using the parameter configuration method.
Supports settings for level two configuration parameters, such as:
C (' USER. USER_ID ', 8);
Configuration parameters are not recommended for more than two levels.
If you want to set multiple parameters, you can use bulk settings, such as:
$config [' user_id '] = 1; $config [' user_type '] = 1; C ($config);
If the first parameter of the C method passes in the array, it represents the bulk assignment, and the above assignment is equivalent to:
C (' user_id ', 1); C (' User_type ', 1);
Get parameters
To get the parameters of the setting, you can use:
$userId = C (' user_id '); $userType = C (' User_type ');
Returns null if the USER_ID parameter has not been defined.
You can also support obtaining level two configuration parameters, such as:
$userId = C (' USER. User_ID ');
If the incoming configuration parameter is empty, it means getting all the parameters:
$config = C ();
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 the
$config = C ("', ' name ');
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.
The above describes the thinkphp function in detail: C method, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.