It’s been a while since I don’t use CI and I’m with a starter doubt.
EDIT:
class MY_Controller extends CI_Controller {
public function __construct() {
parent::__construct();
if(!$this->session->userdata('usuario')) {
$this->load->view('login');
}
}
}
class Home extends MY_Controller {
public function __construct() {
parent::__construct();
Template::set('title', 'Login');
Template::set('view', 'home');
}
public function index() {
$this->load->view('template');
}
}
What happens is that is the user session is invalid, it will load the login view but as in my Home controller contructor method is calling the view home, its loading both views on the same page.
Don’t put this in a hook, put it in
MY_Controllerin the__construct()method.http://codeigniter.com/user_guide/general/core_classes.html
Example:
Just make sure that you extend
MY_Controllerinstead ofCI_Controllerin the controllers you want to run this code in. If you have to change all of them, so be it.UPDATE: You could also try a
post_controller_constructorBut I would still prefer the MY_Controller method, as it is more flexible.