2016-12-02 4 views
0

私はループ状態でメール関数を使用しました。私は使用しました致命的なエラー:codeigniter内の2269行目のsystem/libraries/Email.php内の非オブジェクト上のload()メンバ関数への呼び出し

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

__construct()関数です。

そして、私のメール機能は、メール機能は、ループの最初の時に実行される

$this->email->from('[email protected]', 'fromname'); 
$this->email->to('[email protected]'); 
$this->email->subject('subject'); 
$this->email->message('content_with_header'); 
$this->email->set_mailtype("html"); 
$this->email->send(); 
$this->email->clear(TRUE); 

です。その後、エラーが表示されます

Fatal error: Call to a member function load() on a non-object in /home4/deanjobs/public_html/mywebsite/system/libraries/Email.php on line 2269

誰でも私にこのエラーを修正するのを手伝ってもらえますか?

+0

をロードする必要があります「( '$ this-> load-> libraryメソッドを呼び出しています電子メール '); 'カスタムクラス内? –

+0

いいえ、私は__construct()関数内で使用しています。 –

答えて

0

親コントローラクラスのコンストラクタを呼び出さなかったと思います。

parent::__construct();

これらの行を交換してみてください: あなたのコード: $this->load->library('email'); $this->lang = $this->uri->segment(2, 'nl');

は次のようになります。 $this->lang = $this->uri->segment(2, 'nl'); $this->load->library('email');

+0

いいえ、私は使用しました function __construct() { parent :: __ construct(); $ this-> uri-> segment(2、 'nl'); $ this-> lang = $ this-> uri-> segment(2、 'nl'); } –

+0

次の行を入れ替えてみてください: コード: '$ this-> load-> library( 'email'); $ this-> uri-> segment(2、 'nl'); する必要があります: $ this-> lang = $ this-> uri-> segment(2、 'nl '); $ this-> load-> library( 'email'); ' –

0

それは、コントローラの場合は、あなたのクラスは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('[email protected]', 'fromname'); 
$this->CI->email->to('[email protected]'); 
$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); 
関連する問題