Welcome Guest, Not a member yet? Register   Sign In
Extending CI_Email library does not load config items from config file
#1

[eluser]Ki[/eluser]
I have placed my config items in /config/email.php:
Code:
$config['protocol'] = 'sendmail';
$config['mailtype'] = 'html';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'utf-8';

I have created MY_Email in /application/libraries:
Code:
class MY_Email extends CI_Email {

    function My_Email()
    {
        parent::CI_Email();
    }
}

Within my controller I set:
Code:
$this->load->library('email');

And within Email.php (core CI email library), on line 87 I have added (for testing):

Code:
print_r($config);
if (count($config) > 0)

The above outputs an empty array. If I delete MY_Email.php, then the array outpus the configuration items I have stored.
Shouldn't CI load config items regardless if the library is extended?

Ki
#2

[eluser]Unknown[/eluser]
I know this is a huge necropost, but no one has responded yet, and I had the same problem, so I want to help the others with non-loading config from email.php.

The CI_Email's constructor has the prototype
Code:
function CI_Email($config = array());
so If you create a subclass and want to achieve compatibility, you must keep the constructor's form in subclass.
Code:
function MY_Email($config = array())
    {
        parent::CI_Email($config);
    }
Otherwise CI_Email's constructor will get called without parameters and will default $config to an empty array.




Theme © iAndrew 2016 - Forum software by © MyBB