In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to use the c method in thinkphp. It is very detailed and has a certain reference value. Friends who are interested must finish it.
The c method in thinkphp is a method for setting, getting, and saving configuration parameters, using syntax such as "C ('DB_NAME','thinkphp');", which means that the value of the DB_NAME configuration parameter is set to thinkphp.
This article operating environment: Windows7 system, thinkphp v5.1, Dell G3 computer.
Detailed explanation of ThinkPHP function: C method
The C method is a method used by ThinkPHP to set, obtain, and save configuration parameters, and it is used frequently.
To understand the C method, you need to first understand the configuration of the ThinkPHP, because all the operations of the C method are related to the configuration. The configuration file for ThinkPHP is defined in PHP array format.
As a result of the use of function overloading design, so the use of more, let's explain one by one.
Set parameters
C ('DB_NAME','thinkphp')
Indicates that the value of setting the DB_NAME configuration parameter is thinkphp. Since the configuration parameter is not case-sensitive, the following words are the same: [- more-]
C ('db_name','thinkphp')
However, it is recommended to maintain a uniform uppercase configuration definition specification.
All parameters of the project can be dynamically changed by this method before it takes effect, and the final value will override the definition in the previous setting or convention configuration, or you can use the parameter configuration method to add a new configuration.
Support the setting of secondary configuration parameters, such as:
C ('USER.USER_ID',8)
Configuration parameters are not recommended to exceed level 2.
If you want to set multiple parameters, you can use batch settings, such as:
$config ['user_id'] = 1 * config [' user_type'] = 1 * C ($config)
If the first parameter of the C method is passed into an array, it indicates a batch assignment, which is equivalent to:
C ('USER_ID',1); C (' USER_TYPE',1); [- more-]
Get parameters
To get the set parameters, 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 secondary configuration parameters, such as:
$userId = C ('USER.USER_ID')
If the configuration parameter passed in is empty, all the parameters are obtained:
$config = C ()
Save Settin
Version 3.1 adds a feature to permanently save setting parameters, only in the case of batch assignment, for example:
$config ['user_id'] = 1 * config [' user_type'] = 1 * C ($config,'name')
After the config parameters are set in batches, all current configuration parameters are saved to the cache file (or other configured caching methods).
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 parameters, which must be consistent in order 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 is all the content of the article "how to use the c method in thinkphp". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.