thinkphp Development Framework function Detailed: C method

Source: Internet
Author: User
Keywords Development framework function C method thinkphp
Tags array configuration configuration parameters design development development framework file framework

The C method is thinkphp used to set up, get, and save configuration parameters with a high frequency.
Understanding the C method requires first understanding of the next thinkphp configuration, since all operations of the C method are related to configuration. The thinkphp configuration file is defined using the PHP array format.
Because of the use of function overload design, so the use of more, we come to one by one notes.
Setting parameters

C (' db_name ', ' thinkphp ');

Indicates that the value of setting the Db_name configuration parameter is thinkphp, because the configuration parameters are not case-sensitive, so the following writing is the same:

C (' db_http://www.aliyun.com/zixun/aggregation/11696.html ' >name ', ' thinkphp ');

However, it is recommended that you maintain a uniform capitalization configuration definition specification.
All parameters of a project can be dynamically changed by this method before it takes effect, and the last set value overrides the definition in the previous 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 do not recommend more than two levels.
If you want to set multiple parameters, you can use the batch setting, for example:

$config [' user_id '] = 1; $config [' user_type '] = 1; C ($config);

If the first parameter of the C method passes in an array, it represents a bulk assignment, which 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, the parameters are obtained:

$config = C ();

Save Settings

The 3.1 version adds a feature that permanently saves settings parameters, only for bulk 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 cached file (or other configured caching 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 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 manually merged.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.