【问题标题】:Fatal error: Call to a member function load() on a non-object in system/libraries/Email.php on line 2269 in codeigniter致命错误:在 codeigniter 的第 2269 行对 system/libraries/Email.php 中的非对象调用成员函数 load()
【发布时间】:2016-12-02 06:55:04
【问题描述】:

我在循环条件下使用了邮件功能。我用过

$this->load->library('email');
$this->lang = $this->uri->segment(2, 'nl');

在 __construct() 函数中。

而我的邮件功能是

$this->email->from('from@domain.com', 'fromname');
$this->email->to('to@gmail.com'); 
$this->email->subject('subject');
$this->email->message('content_with_header');
$this->email->set_mailtype("html");
$this->email->send();
$this->email->clear(TRUE);

邮件函数第一次循环执行。之后它显示像

这样的错误

致命错误:在非对象上调用成员函数 load() /home4/deanjobs/public_html/mywebsite/system/libraries/Email.php 在第 2269 行

谁能帮我解决这个错误?

【问题讨论】:

  • 您在自定义类中调用$this->load->library('email'); 吗?
  • 不,我在__construct()函数中使用过。

标签: php codeigniter email


【解决方案1】:

我认为你没有调用父控制器类的构造函数。

parent::__construct();

尝试交换这些行: 你的代码: $this->load->library('email'); $this->lang = $this->uri->segment(2, 'nl');

应该是: $this->lang = $this->uri->segment(2, 'nl'); $this->load->library('email');

【讨论】:

  • 不,我使用过 function __construct() { parent::__construct(); $this->lang = $this->uri->segment(2, 'nl'); }
  • 好的。尝试交换这些行:您的代码:$this->load->library('email'); $this->lang = $this->uri->segment(2, 'nl'); 应该是:$this->lang = $this->uri->segment(2, 'nl'); $this->load->library('email');
【解决方案2】:

确保您的类扩展 CI_Controller(如果它是控制器)。

如果你的类是一个库,你需要加载 Codeigniter 应用实例

function __construct() 
{
    $this->CI =& get_instance();
    $this->CI->load->library('email');
    $this->CI->lang = $this->CI->uri->segment(2, 'nl');
}

在你的邮件功能中

$this->CI->email->from('from@domain.com', 'fromname');
$this->CI->email->to('to@gmail.com'); 
$this->CI->email->subject('subject');
$this->CI->email->message('content_with_header');
$this->CI->email->set_mailtype("html");
$this->CI->email->send();
$this->CI->email->clear(TRUE);

【讨论】:

    猜你喜欢
    • 2013-06-12
    • 2014-05-06
    • 1970-01-01
    • 1970-01-01
    • 2014-10-17
    • 2015-09-25
    • 1970-01-01
    • 1970-01-01
    • 2015-04-14
    相关资源
    最近更新 更多