Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter - accessing $config variable in view

Pretty often I need to access $config variables in views. I know I can pass them from controller to load->view(). But it seems excessive to do it explicitly.

Is there some way or trick to access $config variable from CI views without disturbing controllers with spare code?

like image 513
AlexA Avatar asked Apr 13 '10 16:04

AlexA


People also ask

How to access config variable in CodeIgniter?

The config class function item() is used to get the value of a config variable in Codeigniter. Syntax: $this->config->item('item_name');

How to change config value in CodeIgniter?

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');

How can I access config variable in php?

php include("config. php"); at the top of the PHP file you want to access it in. You will then be able to access the config variables form that PHP file it is declared in.

How add config file in CodeIgniter?

Note: CodeIgniter automatically loads the primary config file ( application/config/config. php ), so you will only need to load a config file if you have created your own. To load one of your custom config files you will use the following function within the controller that needs it: $this->config->load(' filename ');


1 Answers

$this->config->item() works fine.

For example, if the config file contains $config['foo'] = 'bar'; then $this->config->item('foo') == 'bar'

like image 158
Phil Sturgeon Avatar answered Sep 22 '22 04:09

Phil Sturgeon