function analysis of common functions of common/common.php files in thinkphp, _php tutorial

Source: Internet
Author: User
Tags autoload php template tag name smarty template

function analysis of common functions of common/common.php files in thinkphp,


This paper analyzes the functions of thinkphp/common/common.php file. Share to everyone for your reference, as follows:

/** * Get and set configuration parameters support Bulk definition * @param string|array $name Configuration variables * @param mixed $value configuration values * @return mixed */function C ($name =null,  $value =null) {Static $_config = array (); Get all if (empty ($name)) {if (!empty ($value) && $array = cache (' c_ '. $value) without parameters {//array_change_key_ca    SE (): Changes all key names in the array to full lowercase or uppercase, and defaults to full lowercase $_config = Array_merge ($_config, Array_change_key_case ($array));  } return $_config; }//Priority execution set get or assign, if parameter 2 is empty, is the case where the value of the configuration variable is obtained, or if parameter 2 is not NULL, if the value is set for the configuration variable if (is_string ($name)) {//sets the value for the configuration variable or gets the value of the configuration variable if (!STRP OS ($name, '. ')) {//If there is no '. ' In the configuration variable name, execute the following code $name = Strtolower ($name);//Convert the configuration variable name to lowercase if (is_null ($value)) return Isset ($_conf ig[$name])?    $_config[$name]: null;//Gets the configuration variable value, returns the value of the configuration variable $_config[$name] = $value;//sets the value of the configuration variable return;    }//Two-D array set up 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]]: null;//Gets the value of theConditions $_config[$name [0]][$name [1]] = $value;//Assignment return;  }//Bulk Set if (Is_array ($name)) {//Bulk Set Value//array_change_key_case (): Change all the key names in the array to full lowercase or uppercase, default to full lowercase, note: Just change the key name to lowercase oh $_config    = Array_merge ($_config, Array_change_key_case ($name));    if (!empty ($value)) {//Save config Value cache (' C_ '. $value, $_config);  } return; } return null; Avoid illegal parameters}
/** * processing tag extension, such as: Project start tag call, tag (' App_begin '); * @param string $tag tag name * @param mixed $params incoming parameter * @return mixed */function tag ($tag, & $params =null) {//System or frame label Sign extension//C (' extends ', include Think_path. ' conf/tags.php ');//This file is important $extends = C (' extends. $tag);//$_config[' extends '] [App_init]//Application or Project Tag extension//C (' tags ', include conf_path. ' tags.php '); The project can also write its own tags.php file $tags = C (' tags. ' $tag);//$_config[' tags '][app_init] if (!empty ($tags)) {//If $tags is not empty if (Empty ($tags [' _overlay ']) &&!empty ($extends))    {//merge extension $tags = Array_unique (Array_merge ($extends, $tags));    }elseif (Isset ($tags [' _overlay ')) {//By setting ' _overlay ' =>1 override system label unset ($tags [' _overlay ']);  }}elseif (!empty ($extends)) {$tags = $extends;      if ($tags) {if (app_debug) {G ($tag. ' Start ');    Trace (' ['. $tag. ']--start--', ' ', ' INFO ');      }//Execute extension foreach ($tags as $key + $name) {if (!is_int ($key)) {///Specify the full path of the behavior class for pattern expansion $name = $key; }//ChongCCB is a class object such as: $class = $name. ' Behavior '; $behavior = new $class ();//Create a Behavior Class object B ($name, $params);//Perform a behavior, parameter 1-behavior name parameter 2-passed in parameter } if (App_debug) {//record the behavior of the execution log trace (' ['. $tag. ']--end--[RunTime: '. G ($tag. ' Start ', $tag. ' End ', 6). '    S] ', ' ', ' INFO ');  }}else{//did not perform any behavior that returns false to return to false; }}
/** * Execute a behavior * @param string $name behavior name * @param Mixed $params-to-descendant parameters * @return void */function B ($name, & $params =null) {  //The behavior class is automatically loaded in the AutoLoad ($class) function in the Think.class.php file  $class   = $name. ' Behavior ';//The name of the behavior class  G (' Behaviorstart ');  $behavior  = new $class ();//Create a Behavior class object  $behavior->run ($params);//pass parameter  if (app_debug) {//To the current Behavior class object) Record the execution log of the behavior    trace (' Run '. $name. ' Behavior [RunTime: '. G (' Behaviorstart ', ' Behaviorend ', 6). ' S] ', ' ', ' INFO ');}  }

Note: The behavior class, model class, and controller class are automatically loaded in the AutoLoad function in the Think.class.php file:

/*** system automatically loads the Thinkphp class library * and supports configuring the auto-load path * @param string $class object class name * @return void*///behavior class, model class, controller class are automatically loaded through the AutoLoad function public    static function AutoLoad ($class) {//Check if there is an alias definition if (Alias_import ($class)) return; The behavior class is automatically loaded by this function if (substr ($class, -8) = = ' Behavior ') {//Load behavior if (Require_cache (core_path. ' behavior/' $class. class.php ') | | Require_cache (extend_path. ' behavior/'. $class. class.php ') | | Require_cache (lib_path. ' behavior/'. $class. class.php ') | | (Defined (' Mode_name ') && Require_cache (Mode_path.ucwords (mode_name). " /behavior/'. $class.      Class.php ')) {return; }}elseif (substr ($class, -5) = = ' model ') {//Load model if ((Defined (' group_name ') && require_cache (lib_path. ' model/') '. Group_name. ' /'. $class. '. class.php ')) | | Require_cache (lib_path. ' model/'. $class. class.php ') | | Require_cache (extend_path. ' model/'. $class.      Class.php ')) {return; }}elseif (substr ($class, -6) = = ' Action ') {//Load controller if (defined (' group_name ') && require_cache (lib_path. ' action/'). Group_name. ' /'. $class. '. class.php ')) | | Require_cache (lib_path. ' action/'. $class. class.php ') | | Require_cache (extend_path. ' action/'. $class.      Class.php ')) {return;    }}//Try searching according to the automatic load path settings $paths = Explode (', ', C (' App_autoload_path ')); foreach ($paths as $path) {if (Import ($path. '. ').    $class))//returns return if the Load class succeeds; }}

PS: Here are recommended several of the site's formatting/beautification/conversion tools can help you tidy up the messy code, I believe that you can use in future development:

PHP Code online format Beautification tool:
Http://tools.jb51.net/code/phpformat

JavaScript code beautification/compression/formatting/encryption Tools:
Http://tools.jb51.net/code/jscompress

Online XML format/compression tool:
Http://tools.jb51.net/code/xmlformat

JSON Code formatting beautification tool:
Http://tools.jb51.net/code/json

Online Xml/json Mutual Conversion tool:
Http://tools.jb51.net/code/xmljson

JSON code online formatting/landscaping/compression/editing/conversion tools:
Http://tools.jb51.net/code/jsoncodeformat

SQL code online Format beautification tool:
Http://tools.jb51.net/code/sqlcodeformat

More interested in thinkphp related content readers can view this site topic: "thinkphp Introductory Tutorial", "thinkphp Common Method Summary", "PHP Cookie Usage Summary", "Smarty Template Primer Basic Tutorial" and "PHP template technology Summary."

It is hoped that this article is helpful to the PHP program design based on thinkphp framework.

http://www.bkjia.com/PHPjc/1133128.html www.bkjia.com true http://www.bkjia.com/PHPjc/1133128.html techarticle function Analysis of common function of common/common.php file in thinkphp, this paper analyzes the functions of thinkphp/common/common.php file. Share to everyone for your reference, as follows: ...

  • 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.