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

Defining Codeigniter global variables using configuration classes_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 14:58:17749browse

The previously mentioned CodeIgniter introduces custom public functions. This article mentions public function implementation, and global variables can also be implemented with the help of helper functions.

However, a more appropriate way may be to use configuration class definition.

Related downloads: CodeIgniter v1.7.3 open source PHP framework

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, one named Array of $config.

If you need to add global configuration items, you can do it 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:

/**
 * 工作目录配置
 */
$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:

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

Of course, you need to automatically load this configuration file in application/config/autoload.php.

Reference material: http://codeigniter.com/user_guide/libraries/config.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/363826.htmlTechArticleThe previously mentioned CodeIgniter introduces custom public functions. This article mentioned public function implementation, and global variables can also be used. This is achieved with helper functions. However, a more appropriate method...
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