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

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

php - Boolean search on database with 5 million rows, very slow -

css - Text drops down with smaller window -