Using the configuration class to define CodeIgniter global variables _php Tutorial

Source: Internet
Author: User
Tags autoload codeigniter
Public functions in CodeIgniter cannot be appended and can be implemented by helper helpers.
Create a common_helper.php file, define the required public functions, and store them in the Application/helpers directory.
Configure the $autoload in application/config/autoload.php [' helper '] = Array (' common '); Can.

Global variables can also be implemented with helper functions. However, a more appropriate approach may be defined by the configuration class .

The CodeIgniter default has a master configuration file located in the application/config/config.php path, which defines a heap of frame-level global configurations, an array of names called $config.

If you need to add global configuration items that can be implemented in this file, consider the separation of custom configuration and framework configuration, it is recommended to create a new file vars.php, and then do the following definition:

Copy the Code code 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 through the controller in the following code:

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

Or:

Copy the code as follows: $src = $this->config->item (' cache ', ' src ');
Of course, you need to automatically load this configuration file in application/config/autoload.php.

http://www.bkjia.com/PHPjc/788622.html www.bkjia.com true http://www.bkjia.com/PHPjc/788622.html techarticle public functions in CodeIgniter cannot be appended and can be implemented by helper helpers. Create a 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.