The global variables of Codeigniter can also be implemented using the helper function. However, a more appropriate method may be defined using the configuration class. This article mainly introduces how to use the configuration class to define the global variables of Codeigniter. If you need them, refer to the common functions in CodeIgniter that cannot be appended and can be implemented through helper functions.
Create the common_helper.php file, define the required public functions, and store them in the application/helpers directory.
Configure $ autoload ['helper'] = array ('common'); In application/config/autoload. php.
Global variables can also be implemented using the helper function. However, a more appropriate method may be defined using the configuration class..
By default, CodeIgniter has a master configuration file located in the application/config. php path, which defines a bunch of global framework-level configurations and an array named $ 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 youCreate a file vars. phpAnd then make the following definition:
The Code is 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:
The Code is as follows:
$ Src = $ this-> config-> item ('cache', 'src ');
Of course, you need to automatically load this configuration file in application/config/autoload. php.