PHPCMS configuration file Read

Source: Internet
Author: User

---------------------------------------------------------------------------------------------------

Phpcms's entry file index.php in less code, mainly doing three things, as follows:

// 1. Define the PHPCMS root directory (the directory where the portal files are located), Phpcms_path globally available Define dirname (__file__). directory_separator) // 2. Introduction of the Framework entry file (base.php in the framework directory phpcms with the portal file) include Phpcms_path. ' /phpcms/base.php '; // 3. Call the static method Create_app () of the base class Pc_base in the framework portal file to initialize the application Pc_base::create_app ();

Although the code is small, but will do a lot of things in the framework of the import file base.php loaded in, equals directly into the core of the phpcms.

[email protected] Black eyed poet <www.chenwei.ws>---------------------------

Simply say base.php the main things to do:

1. Define a series of constants, such as frame path, cache folder path, etc., globally available.

2. Load frame comes with function library, globally available.

3. By reading the configuration file, the configuration value is defined as a constant and is globally available.

4. With PHPCMS base class (Pc_base), it defines the methods of loading system class, application class, data model, system function library, application function library, plug-in class library, plug-in data model, configuration file, etc.

Define (' Css_path ', pc_base::load_config (' System ', ' Css_path '));

The above defines the CSS path as a constant for the global use of the front and back tables, and how it loads the configuration file, as follows:

/**
* Load configuration file
* @param string $file configuration file
* @param string $key The configuration key to get
* @param string $default default configuration. This value occurs when the Get configuration item fails.
* @param boolean $reload forced reload.
*/
Public Static functionLoad_config ($file,$key= ",$default= ",$reload=false) { Static $configs=Array(); //# defines an empty array that holds configuration values

//-----------------------------------------if(!$reload&&isset($configs[$file]) { //# If Reload and set $configs[$file] (not done here) if(Empty($key)) { return $configs[$file]; /# If the configuration key is empty, return the entire configuration array (the configuration file is returned as a one-dimensional array, such as: return Array (' a ' = = ', ' b ' = = ')} ElseIf(isset($configs[$file][$key])) { return $configs[$file][$key]; //# If a value with a configured key is set, return } Else { return $default; //# defaults back to configuration default } }
//----------------------------------------- $path= Cache_path. ' Configs '. Directory_separator.$file.‘. Php; //# System configuration file path, $path = Phpcms_path. ' Caches/configs/system.php '; if(file_exists($path)) { $configs[$file] =include $path; //# If the system configuration file exists, introduced } if(Empty($key) { //# takes configuration values based on $key, otherwise returns the default value, and the code between dashes return $configs[$file]; } ElseIf(isset($configs[$file][$key])) { return $configs[$file][$key]; } Else { return $default; } }

So when using Load_config (), you simply pass in the configuration file name and configuration key to get the configuration value; The general principle of getting configuration items is similar.

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.