简体   繁体   中英

CodeIgniter undefined variable $config

function index()
{
$this->load->library('email',$config);
}

I have work with Codeigniter mail class and i got undefined variable error.

嗨,我只是删除$ config变量,因为它将自动加载。

$config

Has never been given a value, at least not in the scope that your code is in.

You must do

$config = 'foo';

or something similar, SOMEWHERE within the scope, to initialize it.

You should also use

if(isset($config))

to make sure that it actually exists.

Or just use the ternary operator :

$config = isset($config) ? $config : 'default';

If config is ineed defined somewhere else, then you should pass it as a parameter into the function.

index($config);

the Codeigniter library load syntax is

you have to try to load email class:

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

if you want to config the mail class in loading time then the syntax is :

$this->load->library('email');
// config is 
$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;

$this->email->initialize($config);

and also try this :

$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM