YouTube Icon

Code Playground.

How to set and get config item value in Codeigniter?

CFG

How to set and get config item value in Codeigniter?

Today, i would like to share with you how to set config item value in our codeigniter project. as well as i will share with you how to read that variable value that way we can use global variable in codeigniter 3 application.

We may need to define some global item like site url, site title, site meta data etc that way we can use it in our whole application. So here is very simple and basic example i am going to give you to define set and get config item value in Codeigniter 3 application.

Also Read:-How to Upload Image and Create Thumbnail in CodeIgniter

we will use "$this->config" variable for set configuration item value. we will use "set_item()" and "item()" method for set and get value of array key.

So let's see very basic and simple example for config file item value.

Set Config Value:

$this->config->set_item('mainURL','crowdforgeeks.com');

Also Read:-How to Export Data in Excel format in Codeigniter using PHPExcel Library

Get Config Value:

$mainURL = $this->config->item('mainURL');

Example Config Value:

$this->config->set_item('mainURL','crowdforgeeks.com');
$mainURL = $this->config->item('mainURL');
print_r($mainURL);
exit;

I hope it can help you....




CFG