In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you the thinkPHP configuration of reading and C method example analysis, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!
The details are as follows:
1. Project public configuration
Conf/config.php
The contents are as follows
The 'LOAD_EXT_CONFIG' = >' db,info,email,safe,upfile,cache,route,app,alipay,sms,platform,store,pay' determines which additional configurations are loaded, all of which can be read through the C () method and are valid globally.
two。 If module grouping is enabled, you can define a profile individually for each group, which is located at:
Project configuration directory / group name / config.php
'APP_GROUP_LIST' = >' Home,Admin', / / Project grouping Settings' DEFAULT_GROUP' = > 'Home', / / default grouping
Now that the Home and Admin groups are defined, we can define the grouping profile as follows:
Conf/Home/config.phpConf/Admin/config.php
The configuration file for each grouping is valid only for the current grouping, and the definition format of the grouping configuration is the same as the project configuration.
Note: the grouping name is case sensitive and must be consistent with the defined grouping name.
3. Read configuration
After defining the configuration file, you can use the C method provided by the system (if you find it strange, you can use the Config word to help you remember) to read the existing configuration
C ('parameter name') / / get the parameter value that has been set
For example, C ('APP_STATUS') can read the debug mode settings for the system, and again, because the configuration parameters are not case-sensitive, C (' app_status') is equivalent, but uppercase specifications are recommended.
Returns NULL if the APP_STATUS does not already have a setting.
The C method can also be used to read 2D configurations.
C ('USER_CONFIG.USER_TYPE') / / get the user type settings in the user configuration
The C method reads the global configuration and the configuration of the current module.
If there is no parameter, all valid configurations will be read.
If the same configuration name exists, the previous value will be overwritten.
For example:
'HTML_CACHE_TIME' = > 60, / / static cache validity (seconds)' HTML_CACHE_TIME' = > 80
What you get in the end is 80.
Loading order according to parameter LOAD_EXT_CONFIG
'LOAD_EXT_CONFIG' = >' db,info,email,safe,upfile,cache,route,app,alipay,sms,platform,store,pay'
For example, if there is a parameter HTML_CACHE_TIME of 60 in info, which is not found in other configurations, then this parameter is read out to be 60.
If there is also a HTML_CACHE_TIME of 50 in db, the value is still 60. Because the info is read later, the HTML_CACHE_TIME in the db is overwritten.
Attach the source code of method C
/ * * getting and setting configuration parameters supports batch definition of * @ param string | array $name configuration variable * @ param mixed $value configuration value * @ return mixed * / function C ($name=null, $value=null) {static $_ config = array () / / get all if (empty ($name)) {if (! empty ($value) & & $array = cache ('c_'.$value)) {$_ config = array_merge ($_ config, array_change_key_case ($array));} return $_ config;} / / get or assign if (is_string ($name)) {if (! strpos ($name,'.)) {$name = strtolower ($name) If (is_null ($value)) return isset ($_ config [$name])? $_ config [$name]: null; $_ config [$name] = $value; return;} / / two-dimensional array setting and getting support $name = explode ('.', $name); $name [0] = strtolower ($name [0]) If (is_null ($value)) return isset ($_ config [$name [0]] [$name [1]])? $_ config [$name [0]] [$name [1]]: null; $_ config [$name [0]] [$name [1]] = $value; return;} / / batch if (is_array ($name)) {$_ config = array_merge ($_ config, array_change_key_case ($name)) If (! empty ($value)) {/ / saves the configuration value cache ('cased reading. Avoid valuerequlity config);} return;} return null; / / avoid illegal parameters} these are all the contents of the article "Reading configured in thinkPHP and sample Analysis of C methods". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more 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.