php - Codeigniter, problem with extended class methods -


it’s been while since don’t use ci , i’m 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 user session invalid, load login view in home controller contructor method calling view home, loading both views on same page.

don't put in hook, put in my_controller in __construct() method.

http://codeigniter.com/user_guide/general/core_classes.html

example:

// file application/core/my_controller.php class my_controller extends ci_controller {      function __construct()     {         parent::__construct();         // code here     }  } 

just make sure extend my_controller instead of ci_controller in controllers want run code in. if have change of them, it.

update: try post_controller_constructor

post_controller_constructor

called after controller instantiated, prior method calls happening.

but still prefer my_controller method, more flexible.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -