开发者

codeigniter 2.0.3-Fatal error

I am new to codeigniter and i tried a lesson from one of the tutorials but it throws the following error:

Class 'Controller' not found in 
C:\xampp\htdocs\CodeIgniter\application\controllers\email.php 
on line 3

My code:

<?php

class Email extends Controller{
    function __construct()
    {
        parent::Controller();
    }

    function index()
    {
        $config = Array(
            'protocol' => 'smtp',
            'smtp_host' => 'ssl://smtp.googlemail.com',
            'smtp_port' => 465,
            'username' => 'saveniroj@gmail.com',
            'password' => 'password' 
        );

        $this->load->library('email', $config);
       开发者_开发技巧 $this->email->set_newline("\r\n");

        $this->email->from('saveniroj@gmail.com', 'Niroj Shakya');
        $this->email->to('saveniroj@gmail.com');
        $this->email->subject('This is a test email');
        $this->email->message('Oops This is Great.');

        if($this->email->send())
        {
            echo 'Your email was sent, FOOL';       
        }

        else
        {
            show_error($this->email->print_debugger());
        }
    }
}   

?>

What's the problem?


Change the class definition to

class Email extends CI_Controller {

and in the __construct function

parent::CI_Controller();

In CodeIgniter 2, the default controller is CI_Controller and the default model is CI_Model, whereas in CodeIgniter 1 they were just Controller and Model.


Actually parent::CI_Controller(); needs to be parent::__construct();. PHP will fatal error unless you are on PHP 5.1.x which I believe will alias to PHP 4 style if its missing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜