2013-11-01 29 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