Q: The C function of ThinkPHP is used to obtain configuration parameters. I want to know how to obtain the parameters in the configuration file? FunctionC ($ namenull, $ valuenull) {static $ _ configarra...
Q: The C function of ThinkPHP is used to obtain configuration parameters. I want to know how to obtain the parameters in the configuration file?
- Function C ($ name = null, $ value = null)
- {
- Static $ _ config = array ();
- // Obtain all
- If (emptyempty ($ name) return $ _ config;
- // Get or assign values to the settings
- 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 settings and retrieval 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 settings
- If (is_array ($ name ))
- Return $ _ config = array_merge ($ _ config, array_change_key_case ($ name ));
- Return null; // avoid invalid parameters
- }
- Some parameters are as follows:
- Return array (
-
-
- 'App _ debug' => false, // whether to enable the debugging mode
- 'App _ DOMAIN_DEPLOY '=> false, // whether to deploy the project with an independent domain name
- 'App _ PLUGIN_ON '=> false, // whether to enable the plug-in mechanism
- 'App _ FILE_CASE '=> false, // check whether the file is case-sensitive for Windows platforms
- 'App _ GROUP_DEPR '=>'. ', // delimiter between group modules
- 'App _ GROUP_LIST '=> '', // project grouping settings. multiple groups are separated by commas (,), for example, 'Home, admin'
- 'App _ AUTOLOAD_REG '=> false, // whether to enable SPL_AUTOLOAD_REGISTER
- 'App _ AUTOLOAD_PATH '=> 'Think. Util.', // _ autoLoad mechanism for additional detection path settings, pay attention to the search order
- 'App _ CONFIG_LIST '=> array ('taglibs', 'Routes', 'tags', 'htmls', 'modules', 'actions '), // the configuration list to be loaded for the project. the default options include taglibs (tag library definition), routes (Route definition), tags (tag definition), and htmls static cache definition, modules and actions)
- )
A: This is actually not the problem domain of ThinkPHP. it is the basic knowledge of PHP.
1. as shown in the following figure, config. php directly returns a configuration item array.
- Return array (
-
-
- 'App _ debug' => false, // whether to enable the debugging mode
- 'App _ DOMAIN_DEPLOY '=> false, // whether to deploy the project with an independent domain name
- 'App _ PLUGIN_ON '=> false, // whether to enable the plug-in mechanism
- 'App _ FILE_CASE '=> false, // check whether the file is case-sensitive for Windows platforms
- 'App _ GROUP_DEPR '=>'. ', // delimiter between group modules
- 'App _ GROUP_LIST '=> '', // project grouping settings. multiple groups are separated by commas (,), for example, 'Home, admin'
- 'App _ AUTOLOAD_REG '=> false, // whether to enable SPL_AUTOLOAD_REGISTER
- 'App _ AUTOLOAD_PATH '=> 'Think. Util.', // _ autoLoad mechanism for additional detection path settings, pay attention to the search order
- 'App _ CONFIG_LIST '=> array ('taglibs', 'Routes', 'tags', 'htmls', 'modules', 'actions '), // the configuration list to be loaded for the project. the default options include taglibs (tag library definition), routes (Route definition), tags (tag definition), and htmls static cache definition, modules and actions)
- )
2. you can use $ config = require ("config. php"); to obtain the configuration array, which is simple!
For require, as the name implies, it is used to contain files, corresponding include, and two with once. generally, it includes success return 1, including failure return false,, if return is used in the included file, this value is the return value.