In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you the C method of ThinkPHP development framework functions of the example analysis, I hope you will learn something after reading this article, let's discuss it together!
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:
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)
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 code is as follows:
Class TestAction extends Action {/ * $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) To get a parameter to get a set parameter, you can use: $userId = C ('USER_ID'); $userType = C (' USER_TYPE'); * / public function index () {C ('USER_ID',102); / / assign the parameter C (' USER_TYPE',107); / / assign the parameter dump (C ('USER_ID').') / / 102 = > get the set parameter dump (C ('USER_TYPE')).'; / / 107 = > get the set parameter $this- > display ();}} after reading this article, I believe you have some understanding of "sample Analysis of C method of ThinkPHP Development Framework function". If you want to know more about it, welcome to follow the industry information channel, thank you for reading!
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.