简体   繁体   English

CodeIgniter未定义变量$ config

[英]CodeIgniter undefined variable $config

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

I have work with Codeigniter mail class and i got undefined variable error. 我使用Codeigniter邮件类,但出现未定义的变量错误。

嗨,我只是删除$ 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. 或类似的东西,在范围内的SOMEWHERE中对其进行初始化。

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. 如果在其他地方定义了ine,则应将其作为参数传递给函数。

index($config);

the Codeigniter library load syntax is Codeigniter库的加载语法为

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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