ThinkPHP C function implementation principle

Source: Internet
Author: User
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?

  1. Function C ($ name = null, $ value = null)
  2. {
  3. Static $ _ config = array ();
  4. // Obtain all
  5. If (emptyempty ($ name) return $ _ config;
  6. // Get or assign values to the settings
  7. If (is_string ($ name ))
  8. {
  9. If (! Strpos ($ name ,'.')){
  10. $ Name = strtolower ($ name );
  11. If (is_null ($ value ))
  12. Return isset ($ _ config [$ name])? $ _ Config [$ name]: null;
  13. $ _ Config [$ name] = $ value;
  14. Return;
  15. }
  16. // Two-dimensional array settings and retrieval support
  17. $ Name = explode ('.', $ name );
  18. $ Name [0] = strtolower ($ name [0]);
  19. If (is_null ($ value ))
  20. Return isset ($ _ config [$ name [0] [$ name [1])? $ _ Config [$ name [0] [$ name [1]: null;
  21. $ _ Config [$ name [0] [$ name [1] = $ value;
  22. Return;
  23. }
  24. // Batch settings
  25. If (is_array ($ name ))
  26. Return $ _ config = array_merge ($ _ config, array_change_key_case ($ name ));
  27. Return null; // avoid invalid parameters
  28. }
  29. Some parameters are as follows:
  30. Return array (
  31.  
  32.  
  33. 'App _ debug' => false, // whether to enable the debugging mode
  34. 'App _ DOMAIN_DEPLOY '=> false, // whether to deploy the project with an independent domain name
  35. 'App _ PLUGIN_ON '=> false, // whether to enable the plug-in mechanism
  36. 'App _ FILE_CASE '=> false, // check whether the file is case-sensitive for Windows platforms
  37. 'App _ GROUP_DEPR '=>'. ', // delimiter between group modules
  38. 'App _ GROUP_LIST '=> '', // project grouping settings. multiple groups are separated by commas (,), for example, 'Home, admin'
  39. 'App _ AUTOLOAD_REG '=> false, // whether to enable SPL_AUTOLOAD_REGISTER
  40. 'App _ AUTOLOAD_PATH '=> 'Think. Util.', // _ autoLoad mechanism for additional detection path settings, pay attention to the search order
  41. '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)
  42. )

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.

  1. Return array (
  2.  
  3.  
  4. 'App _ debug' => false, // whether to enable the debugging mode
  5. 'App _ DOMAIN_DEPLOY '=> false, // whether to deploy the project with an independent domain name
  6. 'App _ PLUGIN_ON '=> false, // whether to enable the plug-in mechanism
  7. 'App _ FILE_CASE '=> false, // check whether the file is case-sensitive for Windows platforms
  8. 'App _ GROUP_DEPR '=>'. ', // delimiter between group modules
  9. 'App _ GROUP_LIST '=> '', // project grouping settings. multiple groups are separated by commas (,), for example, 'Home, admin'
  10. 'App _ AUTOLOAD_REG '=> false, // whether to enable SPL_AUTOLOAD_REGISTER
  11. 'App _ AUTOLOAD_PATH '=> 'Think. Util.', // _ autoLoad mechanism for additional detection path settings, pay attention to the search order
  12. '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)
  13. )

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.

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.