thinkphp function Learning (3): C-Function explanation

Source: Internet
Author: User

function C ($name =null, $value =null, $default =null) {    static $_config = Array ();    Get all    if (empty ($name)) {return $_config when no parameters        ;    }    Precedence execution set GET or assign    if (is_string ($name)) {        if (!strpos ($name, '. ')) {            $name = Strtolower ($name);            if (Is_null ($value))                return isset ($_config[$name]) $_config[$name]: $default;            $_config[$name] = $value;            return;        }        Two-dimensional array settings and get 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]]: $default;        $_config[$name [0]][$name [1]] = $value;        return;    }    Bulk set    if (Is_array ($name)) {        $_config = Array_merge ($_config, Array_change_key_case ($name));        return;    }    return null; Avoid illegal parameters}

This is the function defined in the function.php inside the thinkphp.

Detailed

The functions of this function are:

1, get the $_config array, which holds the configuration information (static variables are initialized only once, the function is completed, the value will not disappear)

Print_r (C ()); This will get all the configuration information that has been read or set

2. Read the value of the configuration

echo C (' key '), Echo C (' Key.subkey ');//Read the two-dimensional array, the corresponding configuration file structure is return array (' key ' =>array (' subkey ', ' value ')

  

3, dynamic Add configuration

C (' key ', ' value '); C (' Key.subkey ', ' value ');

  

Key points of C function implementation:

1, Static $_config = Array (); Set the $_config to a static variable so that it can store the value

2, the configuration file of the wording.

return $arr = Array (    ' key1 ' = ' value ';    ' Key2 ' =>array (' subkey ', ' value '),        */* Note the beginning of return, when include this file, returns the return value of this return */

Inspired:

Development projects can be used for reference, the function of the system configuration is still very useful.

  

 

 

thinkphp function Learning (3): C-Function explanation

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.