In the earlier posts we learned about how to create baseurl, custom library, sending email in Codeigniter. Now we can learn about how to read the config file data in the complete application of Codeigniter. It is very tiny but useful when we need to use any variable in several times in the application.

How to read the config file data in the application of Codeigniter

How to read the config file data in the application of Codeigniter – Anil Labs – an Anil Kumar Panigrahi’s technical blog

Below I have taken the example variables which I have taken in send emails using HTML templates in Codeigniter

Config.php code

1
2
3
4
$config['smtp_host'] = 'your domain SMTP host';
$config['smtp_port'] = 25;
$config['smtp_user'] = 'SMTP Username';
$config['smtp_pass'] = 'SMTP Password';

In your controller files or in view page we can directly access it by below code

1
2
3
4
$this->config->item('smtp_host');
$this->config->item('smtp_port');
$this->config->item('smtp_user');
$this->config->item('smtp_pass');

By this we can access these variables through out the application of Codeigniter. If you want to change any any value then change it in config file that will reflect entire application. It looks simple but we need implement it for huge application then debugging will be easy.


0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *