Authentication 在代码点火器中按组加载模板

Authentication 在代码点火器中按组加载模板,authentication,acl,ion-auth,Authentication,Acl,Ion Auth,如何根据组ID的登录用户显示模板,以及如何根据用户组限制对控制器的访问 我的控制器: public function index() { if (!$this->ion_auth->in_group('admin')) { $this->template->administrator('dashboard/dashboard'); } elseif (!$this->ion_auth->in_group('2')

如何根据组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');
    }
}

在尝试和询问之后,最终我得到了正确的结果,可以在以下代码中使用:

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
    }
}
希望这个答案有帮助,并享受编写代码的时间……)