【问题标题】:Load template by groups Ion Auth in Code Igniter在 Codeigniter 中按组 Ion Auth 加载模板
【发布时间】:2016-01-13 10:21:31
【问题描述】:

如何根据组id根据登录用户显示模板以及如何根据用户组限制对控制器的访问。

我的控制器:

public function index()
{
    if (!$this->ion_auth->in_group('admin'))
    {
        $this->template->administrator('dashboard/dashboard');
    }
    elseif (!$this->ion_auth->in_group('2'))
    {
        $this->template->admin('dashboard/dashboard');
    }
    elseif (!$this->ion_auth->in_group('3'))
    {
        $this->template->user('dashboard/dashboard');
    }
    elseif (!$this->ion_auth->in_group('members'))
    {
        $this->template->client('dashboard/dashboard');
    }
    else
    {
        redirect('account/sign_in', 'refresh');
    }
}

【问题讨论】:

    标签: authentication acl ion-auth


    【解决方案1】:

    经过尝试和询问,最终我得到了可以使用的正确结果,如下代码所示:

    public function index()
    {
    
        if (!$this->ion_auth->logged_in())
        {
            redirect('account/sign_in', 'refresh');
        }
        elseif ($this->ion_auth->is_admin())
        {
            $this->template->administrator('dashboard/dashboard');
            //View to Administrator
        }
        elseif($this->ion_auth->in_group('admin'))
        {
            $this->template->admin('dashboard/dashboard');
            //View to Admin
        }
        elseif($this->ion_auth->in_group('user'))
        {
            $this->template->user('dashboard/dashboard');
            //View to User
        }
        else
        {
            $this->template->client('dashboard/dashboard');
            //View to Client
        }
    }
    

    希望这个答案对您有所帮助并享受编写代码的时光...... :)

    【讨论】:

      猜你喜欢
      • 2018-03-01
      • 1970-01-01
      • 2013-08-31
      • 2013-02-11
      • 1970-01-01
      • 2016-07-16
      • 1970-01-01
      • 2012-05-30
      • 2011-10-12
      相关资源
      最近更新 更多