CI Frame source Pages-config.php

Source: Internet
Author: User
Tags codeigniter
CI Framework source Reading---------config.php
File address:./system/core/config.php
Primary role: Management configuration
1. member Properties $config List of values for all loaded configurations
2. member Properties $is_loaded List of all loaded configuration files
3. member Properties $_config_paths Search for a list of paths when a configuration file needs to be loaded
4.__construct () The constructor method automatically executes this method first
There are two main things that it does. A) Gets the configuration assignment to the member property $config
b) Set the Base_url in the configuration
5.load ($file = ", $use _sections = False, $fail _gracefully = False)
Load configuration file
$file is the file name of your custom configuration file, this file name does not have a. php extension.
$use _sections If you need to load multiple custom profiles, they will typically be merged into an array. However, if an index with the same name exists in a different configuration file, a conflict occurs. To avoid this problem, you can set the second parameter to TRUE, which allows the contents of each configuration file to be stored in a separate array, and the index of the array is the file name of the configuration file.
$fail _gracefully Allow masking of error messages that occur when a configuration file does not exist:
(0) filter and set $file variable
(1) Initialize $FOUNF False to determine if the file exists
(2) Initialize $loaded False to determine if the file is loaded
(3) Detecting file paths If an environment variable is added to the environment variable
(4) Go to the foreach traversal file path and find out if the file is loaded and exists
(5) If the file does not exist outside the Foreach Loop
(6) Loading files
(7) Determine if $config exists, this $config should be defined in the loaded file
(8) Judging $use_sections If true, the contents of each configuration file are stored in a separate array, and the index of the array is the file name of the configuration file.
If False, all configuration files are merged into an array
(9) Add the file into the is_loaded array and destroy the $config
(ten) $loaded set to true log record jumps out of loop
(11) If Loaded is false and $fail_gracefully is not equal to true display error log


6.item () Get a configuration item
$item The name of the configuration item
$index If the configuration is an array, this item is the array index name
(1) Determine if index is empty
(2) If index is empty, determine if $this->config[$item] exists, if there is no return, present, assign to $pref
(3) If index is not empty, judge whether $this->config[$index] exists, judge whether $this->config[$index [$item] exists, will $this->config[$index][$ Item] Assignment to $pref
(4) Return to $pref


7.slash_item () Get a configuration item and add/
$item The name of the configuration item
(1) Determine if a configuration item exists that does not exist return false
(2) Determine if the configuration item is empty if NULL returns '
(3) Add/And return after the configuration value.


8.site_url () This function gets the URL of your website, which contains the value of "index" that you set in the config file.
$uri The URI string is the parameter that the access path takes
(1) If $uri = "returns a URL consisting of Base_url and index_page
(2) Judge $this->item (' enable_query_strings ') True and false, and return different forms of address. (This item is configured in the application/config/config.php file.) It is used to distinguish the method of example.com/who/what/where/, if False is the default method of parameter transfer. If true, this is the way to example.com/index.php?c=controller&m=function such a parameter. )

9.base_url () This function returns the root URL of the site, where you can stitch a URL path to generate a URL for a CSS or picture file.

10._uri_string () constructs a URI string to let Site_url (), Base_url () two functions use.


11.system_url () This function gets the URL of the system folder.


12.set_item () Setting a configuration item


13._assign_to_config () sets multiple configuration items (in the form of an array key is the name of the configuration item to be set, value is the values of the configuration item)


Source:

 Config =& get_config (); Log_message (' Debug ', "config Class Initialized");//Set the base_url automatically if none was Provided if ($this->config[' base_url '] = = ") {if (Isset ($_server[' http_host '))) {$base _url = isset ($_server[' HTTPS ']) && strtolower ($_server[' https ')!== ' off '? ' https ': ' http '; $base _url. = '://'. $_server[' http_host '; $base _url. = Str_replace (basename ($_server[' script_name ']), ' ', $_server[' script_name ']);} else{$base _url = ' http://localhost/';} $this->set_item (' Base_url ', $base _url);}}   --------------------------------/** * Load Config file * * @accesspublic * @paramstringthe Config file name * @param Boolean if configuration values should be loaded to their own section * @param boolean True if errors should just re Turn false, False if an error message should is displayed * @returnbooleanif the file was loaded correctly */function load ($file = ", $use _sections = False, $fail _gracefully = False) {$file = ($file = = ")? ' Config ': str_replaCE ('. php ', ', $file); $found = false; $loaded = false; $check _locations = defined (' Environment ')? Array (environment. ' /'. $file, $file): Array ($file); foreach ($this->_config_paths as $path) {foreach ($check _locations as $location) {$ File_path = $path. ' config/' $location. '. PHP '; if (In_array ($file _path, $this->is_loaded, TRUE)) {$loaded = True;continue 2;} if (file_exists ($file _path)) {$found = True;break;}} if ($found = = = FALSE) {continue;} Include ($file _path), if (! isset ($config) OR! Is_array ($config)) {if ($fail _gracefully = = TRUE) {return FALSE;} Show_error (' Your '. $file _path. ' File does not appear to contain a valid configuration array. ');} if ($use _sections = = TRUE) {if (Isset ($this->config[$file])) {$this->config[$file] = Array_merge ($this- config[$file], $config);} else{$this->config[$file] = $config;}} else{$this->config = Array_merge ($this->config, $config);} $this->is_loaded[] = $file _path;unset ($config) $loaded = true;log_message (' debug ', ' Config file loaded: '. $filE_path); break;} if ($loaded = = = False) {if ($fail _gracefully = = = TRUE) {return false;} Show_error (' The configuration file '. $file. PHP does not exist. ');} return TRUE;} --------------------------------/** * Fetch, get a config file item * * * @accesspublic * @paramstringthe config item Name * @paramstringthe Index name * @parambool * @returnstring */function item ($item, $index = ') {if ($index = = ") {if ( ! Isset ($this->config[$item])) {return FALSE;} $pref = $this->config[$item];} Else{if (! isset ($this->config[$index])) {return FALSE;} if (! isset ($this->config[$index [$item])) {return FALSE;} $pref = $this->config[$index] [$item];} return $pref;} --------------------------------/** * Fetch a config file Item-adds slash after item (if item was not empty) * * @acce Sspublic * @paramstringthe Config Item name * @parambool * @returnstring */function Slash_item ($item) {if (! isset ($this-& gt;config[$item])) {return FALSE;} if (Trim ($this->config[$item]) = = ') {return ';} ReturnRTrim ($this->config[$item], '/'). ' /';} --------------------------------/** * Site URL * Returns base_url.  Index_page [. uri_string] * * @accesspublic * @paramstringthe URI String * @returnstring */function site_url ($uri = ") {if ($uri = = ") {return $this->slash_item (' Base_url '). $this->item (' Index_page ');} if ($this->item (' enable_query_strings ') = = False) {$suffix = ($this->item (' url_suffix ') = = False)? ": $this->item (' Url_suffix '); return $this->slash_item (' Base_url '). $this->slash_item (' Index_page '). $ This->_uri_string ($uri). $suffix;} Else{return $this->slash_item (' Base_url '). $this->item (' Index_page '). $this->_uri_string ($uri);}} -------------------------/** * Base URL * Returns base_url [. uri_string] * * @access public * @param string $uri * @re Turn string */function base_url ($uri = ") {return $this->slash_item (' Base_url '). LTrim ($this->_uri_string ($uri) , '/');} -------------------------/** * Build URI string for use in Config::site_urL () and Config::base_url () * * @access protected * @param $uri * @return string */protected function _uri_string ($uri) {if ($this->item (' enable_query_strings ') = = FALSE) {if (Is_array ($uri)) {$uri = implode ('/', $uri);} $uri = Trim ($uri, '/');} Else{if (Is_array ($uri)) {$i = 0; $str = "; foreach ($uri as $key + = $val) {$prefix = ($i = = 0)? ': ' & '; $str. = $prefix. $key. ' = '. $val; $i + +;}    $uri = $str;}} return $uri;} --------------------------------/** * System URL * * @accesspublic * @returnstring */function System_url () {$x = explode ("/", Preg_replace ("|/*" (. +?) /*$| "," \\1 ", BasePath)); return $this->slash_item (' Base_url '). End ($x). ' /';} --------------------------------/** * Set a config file item * * @accesspublic * @paramstringthe config item key * @par Amstringthe Config Item value * @returnvoid */function set_item ($item, $value) {$this->config[$item] = $value;} --------------------------------/** * Assign to Config * * This function was called by the front controller (Codeigniter.php) * After the Config class is instantiated. It permits config items * To is assigned or overriden by variables contained in the index.php file * * @accessprivate * @p Aramarray * @returnvoid */function _assign_to_config ($items = Array ()) {if (Is_array ($items)) {foreach ($items as $key =&gt ; $val) {$this->set_item ($key, $val);}}} End Ci_config class/* end of file config.php *//* location:./system/core/config.php */


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