How to Get and Set Config Variables in Codeigniter?

By Hardik Savani November 5, 2023 Category : PHP 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.

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','itsolutionstuff.com');

Get Config Value:

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

Example Config Value:

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


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


print_r($mainURL);

exit;

I hope it can help you....

Shares