php - Why I can't use sessions in a CodeIgniter hook -
i have code here: hooks/account.php:
class account { public function checkiflogged() { if(!$this->session->userdata('logged') ){ $this->load->view('error/not_found'); exit; } } }
and error:
undefined property: account::$session
i can confirm hook post_controller_constructor.
can tell me going wrong?
thanks.
you should use:
$this->ci = & get_instance(); if(!$this->ci->session->userdata('logged') ){ $this->ci->load->view('error/not_found'); exit; }
it's matter of scope that's why use ci here way.
Comments
Post a Comment