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

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -