2016-01-13 25 views
0

如何根據登錄用戶按組id來顯示模板,以及如何根據用戶組限制對控制器的訪問。按組加載模板代碼點火器中的Ion Auth

我的控制器:

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

回答

0

努力並詢問後,終於,我感到我可以如下面的代碼中使用了正確的結果:

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 
    } 
} 

希望這個答案有幫助,享受時間代碼...... :)