Загрузить шаблон по группам Ion Auth в Code Igniter

Как показать шаблон по логину пользователя по группам и как ограничить доступ к контроллеру по группам пользователей.

Мой контроллер:

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');
    }
}

person 301_Redirect    schedule 13.01.2016    source источник


Ответы (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
    }
}

Надеюсь, этот ответ будет полезен, и вы получите удовольствие от написания кода..... :)

person 301_Redirect    schedule 21.01.2016