Blog Details

Config Class


* Config Class :-

  • The Config class provides a means to retrieve configuration preferences.
  • These preferences can come from the default config file ( application/config/config.php)or from your own custom config files. 

* Loading a Config File :-

  • There are two ways to load a config file:

1) Manual Loading :-

  • To load one of your custom config files you will use the following function within the controller  that needs it:
  • $this->config->load('filename');
  • Where filename is the name of your config file, without the .php file extension.

2) Auto-loading :-

  • If you find that you need a particular config file globally, you can have it loaded automatically by the system. To do this, open the autoload.php file, located at  aplpication/config/autoload.php , and add your config file as indicated in the file. 

* Fetching Config Items :-

  • To retrieve an item from your config file, use the following function:
  • $this->config->item('item name');
  • Where item name is the $config array index you want to retrieve. For example, to fetch your language choice you'll do this:
  • $lang = $this->config->item('language');
  • The function returns FALSE (boolean) if the item you are trying to fetch does not exist.
  • If you are using the second parameter of the $this->config->load function in order to assign your config items to a specific index you can retrieve it by specifying the index name in the second parameter of the $this->config->item() function.
  Example :   / Loads a config file named blog_settings.php and assigns it to an index named "blog_settings" $this->config->load('blog_settings', TRUE); // Retrieve a config item named site_name contained within the blog_settings array $site_name = $this->config->item('site_name', 'blog_settings'); // An alternate way to specify the same item: $blog_config = $this->config->item('blog_settings'); $site_name = $blog_config['site_name'];  

* Setting a Config Item :-

  • If you would like to dynamically set a config item or change an existing one, you can do so using:
  • $this->config->set_item('item_name', 'item_value');
  • Where item_name is the $config array index you want to change, and item_value is its value.

* Helper Functions :-

  • The config class has the following helper functions:

1) $this->config->site_url();

  • This function retrieves the URL to your site, along with the "index" value you've specified in the config file.

2) $this->config->base_url();

  • This function retrieves the URL to your site, plus an optional path such as to a stylesheet or image.
  • The two functions above are normally accessed via the corresponding functions in the URL Helper.

3) $this->config->system_url();

  • This function retrieves the URL to your system folder.



Latest posts

Implementing CRUD Operations ¶

<ul> <li>Now comes the fun part. We would like t


<ol> <li><a href="

Creating Model

<ol> <li><a href="

Get Free Quote