dongyi3616 2014-02-10 15:08
浏览 101
已采纳

CodeIgniter Ion Auth:is_admin()是如何工作的?

I'm using the Ion_auth for CodeIgniter in my project auth library. I'm trying to make a similar function as is_admin() for other user types (there are three user types other than the admin) to check whether the logging in user is of one of those three types so I can redirect them to their respective pages. Ion_auth is using an event called is_admin but I can't understand where this is happening in the Ion_auth_model.php and how it checks whether the logged in user is admin. So how can I make other functions/events similar to this one?

I know I can just do something like query the database and check the user group but I want to do the way Ion_auth has done. That way I can also satisfy myself by actually understanding the stock code.

  • 写回答

2条回答 默认 最新

  • doubi3929 2014-02-10 17:58
    关注

    I am just looking at source code on github.

    As lots of auth libraries store, information you are looking for in session and library itself checks session variables.

    your function you are looking for is on line 447 in file application/libraries/Ion_auth.php

    public function is_admin($id=false)
        {
            $this->ion_auth_model->trigger_events('is_admin');
    
            $admin_group = $this->config->item('admin_group', 'ion_auth');
    
            return $this->in_group($admin_group, $id);
        }
    

    In order to create your own I suggest you to reverse engeneer model (ion_auth_model.php)

    But! Ion already has a workaround for you, this method is what you are looking for

    in_group()

    $group = 'gangstas';
        if (!$this->ion_auth->in_group($group))
        {
            $this->session->set_flashdata('message', 'You must be a gangsta to view this page');
            redirect('welcome/index');
        }
    

    source

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 Hyper-v虚拟机相关问题,求解答。
  • ¥15 TSM320F2808PZA芯片 Bootloader
  • ¥30 谷歌浏览器出现开发者工具无法显示已创建的,但您可以调试已部署的代码。 状态代码 404, net::ERR HTTP RESPONSE CODE FAILURE
  • ¥15 chatgpt网页版侧边栏和模型切换点击没反应怎么办
  • ¥15 dev运行环境,c语言,报错是为什么?怎么改
  • ¥15 如何解决蓝牙通话音频突发失真问题
  • ¥15 安装opengauss数据库报错
  • ¥15 【急】在线问答CNC雕刻机的电子电路与编程
  • ¥60 在mc68335芯片上移植ucos ii 的成功工程文件
  • ¥15 笔记本外接显示器正常,但是笔记本屏幕黑屏