Yekver
Yekver

Reputation: 5185

codeigniter view in construct

class Index extends MY_Controller {
     public function __construct() {
          parent::__construct();
     }
}

class MY_Controller extends CI_Controller{
    function __construct(){
        parent::__construct();
        $this->load->view('index');
        die();
    }
}

Why in this way the view is not rendering in browser?

Can I use something like this as a solution? Or there is another better way?

class MY_Controller extends CI_Controller{
    function __construct(){
        parent::__construct();
        $this->load->view('index');
        $this->CI =& get_instance();
        $this->CI->output->_display();
        exit();
    }
}

Upvotes: 0

Views: 2048

Answers (1)

mahadeb
mahadeb

Reputation: 676

Because you are using die() after loading view, remove that line it will work.

Upvotes: 1

Related Questions