dongqiang2069 2015-05-04 20:22
浏览 64
已采纳

codeigniter在非对象上调用成员函数is_admin()

I am getting this error when i try to login to my admin page where i ask it to verify the credentials

here are some snippets:

// Tank_Auth.php Line 71
$this->ci->session->set_userdata(array(
    'is_admin'  => (bool) $user->is_admin, // added
    'user_id'   => $user->id,
    'username'  => $user->username,
    'status'    => ($user->activated == 1) ? STATUS_ACTIVATED : STATUS_NOT_ACTIVATED,
));
function is_admin()
{
    return $this->logged_in() && $this->ci->session->userdata('is_admin') === TRUE;
}


// controllers/auth.php Line 30
function login()
{
    if ($this->tank_auth->is_admin()) {
        redirect('admin');
    } elseif ($this->tank_auth->is_logged_in()) {
        redirect('user');
    }

so i though if i added this to my login page it would verify that i am an admin:

public function index() {

   if ($this->tank_auth->is_admin())  {
        redirect('admin/dashboard');
    } else {
    $this->load->view('admin/vwLogin');
    }
}

Can anybody help me with this please? i am really lost now on how to solve this.

  • 写回答

1条回答 默认 最新

  • dongtingxiao4697 2015-05-04 20:24
    关注

    In codeigniter,

    before calling model (tank_auth: I assume that this is a model) , you need to load that file.

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

    PS: your model file must be inside model folder. If you have one more folder inside that, then:

    $this->load->model('/extra_folder_name/tank_auth');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 请求分析基于spring boot+vue的前后端分离的项目
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?