Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom config files - Codeigniter

i try to create my custom email config file that includes my email server configuration.

i created it under /config directory and the code is below:

<?php

$config = Array(
            'protocol' => 'smtp',
            'smtp_host' => 'ssl://smtp.googlemail.com',
            'smtp_port' => 465,
            'smtp_user' => '[email protected]',
            'smtp_pass' => '*************',
            'mailtype' => 'html'
        );




        $this->load->library('email', $config);
        $this->email->set_newline("\r\n");

?>

and in order to use it i call in my kayit.php's which is a controller constructor

 $this->config->load('email'); 

However, i get an error like that enter image description here

like image 861
Mert METİN Avatar asked Dec 02 '22 23:12

Mert METİN


2 Answers

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!

like image 120
Damien Pirsy Avatar answered Jan 01 '23 14:01

Damien Pirsy


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'] = '[email protected]';
$config['smtp_pass'] = '*************';
$config['mailtype']= 'html';
like image 44
Rocket Hazmat Avatar answered Jan 01 '23 14:01

Rocket Hazmat