Use the configuration class to define the global variables of Codeigniter. Previously mentioned introduction of custom public functions to CodeIgniter this article mentioned the implementation of public functions. global variables can also be implemented using the helper function. However, CodeIgniter, which is more appropriate, introduced a user-defined public function. This article mentions public function implementation. global variables can also be implemented using the helper function.
However, a more appropriate method may be defined using the configuration class.
Related downloads:CodeIgniter v1.7.3 open-source PHP Framework
By default, CodeIgniter has a master configuration file located inApplication/config. php path, which defines a bunch of framework-level global configurations, a name is$ Config.
If you need to add a global configuration item, you can implement it in this file. Considering the separation of custom configuration and framework configuration, we recommend that you create a new file vars. php and then define it as follows:
/*** Working directory configuration */$ config ['src'] ['cache'] = FCPATH. '.. /src/cache '; $ config ['src'] ['modules'] = FCPATH. '.. /src/modules '; $ config ['src'] ['WWW'] = FCPATH. '.. /src/www ';
Use the following code to read data from the controller:
$src = $this->config->item('src');$cache = $src['cache']
Or:
$src = $this->config->item('cache', 'src');
Of course, you need to automatically load this configuration file in application/config/autoload. php.
References: http://codeigniter.com/user_guide/libraries/config.html
CodeIgniter Introduces Custom public functions. This article mentions public function implementation. global variables can also be implemented using the helper function. However, it is more appropriate...