Custom config files - Codeigniter Custom config files - Codeigniter codeigniter codeigniter

Custom config files - Codeigniter


I quote from the manual:

If you prefer not to set preferences using the above method, you can instead put them into a config file. Simply create a new file called the email.php, add the $config array in that file. Then save the file at config/email.php

The config file is just AN ARRAY (named $config), and being only that it doesn't have access to the $this reference. The code you're using (loading a library, for example) has to be inside a controller, not inside the config file!


Since this config file is for the built-in email class, it will be auto-loaded if it's called config/email.php.

If you prefer not to set preferences using the above method, you can instead put them into a config file. Simply create a new file called the email.php, add the $config array in that file. Then save the file at config/email.php and it will be used automatically. You will NOT need to use the $this->email->initialize() function if you save your preferences in a config file.

You cannot (why would you) call $this->load inside a config file.

Also, you cannot declare config files like that. $config = Array(, you are overwriting all other values in $config. You need to declare each option individually.

$config['protocol'] = 'smtp';$config['smtp_host'] = 'ssl://smtp.googlemail.com';$config['smtp_port'] = 465;$config['smtp_user'] = 'mertmetinbjk@gmail.com';$config['smtp_pass'] = '*************';$config['mailtype']= 'html';


You need to create a file named email.php in ./application/config/ folder and in that file create an array with your values. In your case it should be

$config = Array(        'protocol' => 'smtp',        'smtp_host' => 'ssl://smtp.googlemail.com',        'smtp_port' => 465,        'smtp_user' => 'mertmetinbjk@gmail.com',        'smtp_pass' => '*************',        'mailtype' => 'html'    );

Now whenever you load the email library in your application it overrides the default configuration with this. Remember the array name must be config.