Home  >  Article  >  Backend Development  >  Define Codeigniter global variables using configuration classes_PHP tutorial

Define Codeigniter global variables using configuration classes_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:28:30978browse

Public functions in CodeIgniter cannot be appended and can be implemented through helper auxiliary functions.
Create the common_helper.php file, define the required public functions, and store it in the application/helpers directory.
Configure $autoload['helper'] = array('common'); in application/config/autoload.php.

Global variables can also be implemented with helper functions. However, a more appropriate way may be to use configuration class definition .

CodeIgniter has a main configuration file by default, located in the application/config/config.php path, which defines a bunch of framework-level global configurations, an array named $config.

If you need to add global configuration items, you can do so in this file. Considering the separation of custom configuration and framework configuration, it is recommended to create a new file vars.php, and then define it as follows:

Copy code 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';
When used, read in the controller through the following code:

$src = $this->config->item('src');
$cache = $src['cache']

or:

Copy code 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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/788622.htmlTechArticlePublic functions in CodeIgniter cannot be appended and can be implemented through helper auxiliary functions. Create the common_helper.php file, define the required public functions, and store it in the application/helpers directory...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn