Read the PHPCMS configuration file

Source: Internet
Author: User

Bytes ---------------------------------------------------------------------------------------------------

The entry file index. php of PHPCMS has less code and mainly involves three things:

// 1. define the PHPCMS root directory (the directory where the entry FILE is located), and define ('phpcms _ path', dirname (_ FILE _) is available globally for PHPCMS_PATH __). DIRECTORY_SEPARATOR) // 2. introduce the framework entry file (base in the framework directory phpcms, which is the same as the entry file. php) include PHPCMS_PATH. '/phpcms/base. php '; // 3. call the static method create_app () of the base class pc_base in the framework entry file to initialize the pc_base: create_app ();

Although there are few codes, after loading base. php, the Framework entry file that has done a lot of work, it is equivalent to directly entering the core of PHPCMS.

--------------------------- @ Chenwei black-eye poet <www. chenwei. ws> ---------------------------

Let's briefly describe what base. php mainly does:

1. Define a series of constants, such as the Framework path and cache folder path, which are globally available.

2. Load built-in function libraries for global availability.

3. Read the configuration file and define the configuration value as a constant, which is globally available.

4. the built-in PHPCMS base class (pc_base) defines methods for loading the system class, application class, data model, system function library, application function library, plug-in class library, plug-in data model, and configuration file.

 

Define ('css _ path', pc_base: load_config ('system', 'css _ path '));

The CSS path is defined as a constant so that the front and back ends can be used globally. The following method is used to load the configuration file:

/**
* Load the configuration file
* @ Param string $ file configuration file
* @ Param string $ key the configuration key to be obtained
* @ Param string $ default configuration. This value takes effect when the configuration item fails to be obtained.
* @ Param boolean $ reload force reload.
*/
Public static function load_config ($ file, $ key = '', $ default ='', $ reload = false) {static $ configs = array (); // # define an empty array for storing configuration values

// ------------------------------------------- If (! $ Reload & isset ($ configs [$ file]) {// # If you reload and set $ configs [$ file] (not executed here) if (empty ($ key) {return $ configs [$ file]; // # if the configuration key is empty, the entire configuration array is returned (the configuration file is returned in a one-dimensional array, for example, return array ('A' => '', 'B' =>'')} elseif (isset ($ configs [$ file] [$ key]) {return $ configs [$ file] [$ key]; // # If the configuration key value is set, return} else {return $ default; // # default return configuration default }}
// ------------------------------------------- $ Path = CACHE_PATH. 'configs '. DIRECTORY_SEPARATOR. $ file. '. php '; // # path of the system configuration file, $ path = PHPCMS_PATH. 'caches/configs/system. php '; if (file_exists ($ path) {$ configs [$ file] = include $ path; // # if the system configuration file exists, introduction} if (empty ($ key) {// # obtain the configuration value based on $ key; otherwise, the default value is returned. The Code return $ configs [$ file] between the dotted line and above;} elseif (isset ($ configs [$ file] [$ key]) {return $ configs [$ file] [$ key];} else {return $ default ;}}

Therefore, when load_config () is used, you only need to input the configuration file name and key to obtain the configuration value. The principle of obtaining a configuration item 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.