2013-05-12 32 views
0

我有這樣的代碼在這裏: 鉤/ account.php:爲什麼我不能在笨鉤使用會話

class Account { 

    public function checkIfLogged() { 
     if(!$this->session->userdata('logged')){ 
      $this->load->view('error/not_found'); 
      exit; 
     } 
    } 
} 

,我得到這個錯誤:

Undefined property: Account::$session

我可以證實我的鉤子是一個post_controller_constructor。

有人可以告訴我我要去哪裏嗎?

謝謝。

回答

4

你應該使用:

$this->CI = & get_instance(); 
if(!$this->CI->session->userdata('logged')){ 
     $this->CI->load->view('error/not_found'); 
     exit; 
} 

這只是一個範圍,這就是爲什麼你使用CI這裏這樣的事。

+0

它工作的很棒:) – 2013-05-12 22:51:11

相關問題