我正在为使用 Codeigniter V 2.1.4 中的 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
该代码一次工作,但即使它这样做了,当我从 flexi_auth 调用函数 is_admen() 时它也抛出了同样的错误。Flexi_auth.php 和 Flexi_auth_lite.php 位于 application/libraries 目录中。