thinkphp Function: C method

Source: Internet
Author: User

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

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.