问题
I have this code here: hooks/account.php:
class Account {
public function checkIfLogged() {
if(!$this->session->userdata('logged') ){
$this->load->view('error/not_found');
exit;
}
}
}
and I get this error:
Undefined property: Account::$session
I can confirm that my hook is a post_controller_constructor.
Can somebody tell me where I am going wrong?
Thanks.
回答1:
you should use:
$this->CI = & get_instance();
if(!$this->CI->session->userdata('logged') ){
$this->CI->load->view('error/not_found');
exit;
}
It's just a matter of scope that's why you use CI here this way.
来源:https://stackoverflow.com/questions/16512799/why-i-cant-use-sessions-in-a-codeigniter-hook