2013-11-01 27 views
1

我正在使用Codeigniter V 2.1.4中的Flexi Auth在網站上登錄系統。我正在嘗試將用戶的登錄狀態傳遞給一個菜單,該菜單根據用戶是否已登錄而動態更改。這是我使用的代碼:Codeigniter Flexi Auth庫有時會加載

public function create_page($pgName = 'home') 
{ 

    $this->config->load('tera_site', TRUE); 
    $this->load->library('flexi_auth_lite'); 

    // Cunstruct Page data 
    $data['pgName'] = $pgName; 

    if ($this->session->userdata('admin') === FALSE){$data['admin'] = 0;}else{$data['admin'] = $this->session->userdata('admin');} 
    $data['siteTitle'] = $this->config->item('siteTitle','tera_site'); 


    // This is the line the Error is thrown from: 
    $data['loggedIn'] = $this->flexi_auth_lite->is_logged_in(); 


    $data['header'] = $this->load->view('include/header', $data, TRUE); 
    $data['pages'] = $this->config->item('pages','tera_site'); 
    $data['footer'] = $this->load->view('include/footer', False, TRUE); 
    $data['sideBar'] = $this->load->view('include/side_bar_view', $data, TRUE); 


    $this->load->model('page_model'); 

    $data['pgData'] = $this->page_model->getPage($pgName); 

    // load the Catcha Library 
    $this->load->library('captcha_my'); 

    if($data['pgData']['Captcha'] = 1) { 

    $data['Captcha'] = $this->captcha_my->createCaptcha(); 

    } else if ($this->session->userdata('captchaCheck') == true) { 

     $data['Captcha'] = $this->captcha_my->createCaptcha(); 

} 

return $data; 

這是錯誤:

Severity: Notice 
Message: Undefined property: Main::$flexi_auth_lite 
Fatal error: Call to a member function is_logged_in() on a non-object 

的代碼工作在同一時間,但即使這樣做是扔了同樣的錯誤,當我調用的函數is_admen ()來自flexi_auth。 Flexi_auth.php和Flexi_auth_lite.php位於應用程序/庫目錄中。

如果你看看演示文件

回答

0

,有一個控制器「auth_lite.php」 它說

// IMPORTANT! This global must be defined BEFORE the flexi auth library is loaded! 
// It is used as a global that is accessible via both models and both libraries, without it, flexi auth will not work. 
$this->auth = new stdClass; 

// Load 'lite' flexi auth library by default. 
// If preferable, functions from this library can be referenced using 'flexi_auth' as done below. 
// This prevents needing to reference 'flexi_auth_lite' in some files, and 'flexi_auth' in others, everything can be referenced by 'flexi_auth'. 
$this->load->library('flexi_auth_lite', FALSE, 'flexi_auth'); 
+0

我已經在做兩個,第二個是可選 – John