Use the configuration class to define the Codeigniter global variable _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Use the configuration class to define the global variables of Codeigniter. Public functions in CodeIgniter cannot be appended. they can be implemented using helper functions of helper. Create the common_helper.php file, define the required public functions, and store them in the applicationhelpers Directory. the public functions in CodeIgniter cannot be appended, and can be implemented through the helper auxiliary function.
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.

Helper function implementation. Create the common_helper.php file, define the required public functions, and store them in the application/helpers directory...

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.