1

我正在为使用 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 目录中。

4

1 回答 1

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');
于 2013-11-24T12:56:32.203 回答