2010-08-11 84 views
0

我剛剛在我的Codeigniter應用程序中使用並安裝了IonAuth。Codeigniter IonAuth Library - 羣組成員登錄後重定向

我已經安裝3個用戶組。

聯繫
成員
合作媒體

是否可以給每個用戶組重定向到其獨特的儀表盤區域,而不是主頁?

例如

管理員登錄並重定向到=>/admin/dashboard/
會員登錄並重定向到=>/users/dashboard/
媒體合作伙伴登錄並重定向到=>/media-info/dashboard/

我怎麼會去這我的認證控制器?

謝謝,丹

回答

1

在您的登錄功能檢查組,並相應地重定向。

function login() 
{ 
    //Login code 
    ... 
    //Login Successful 
    $user = $this->ion_auth->get_user(); 

    switch ($user->group) 
    { 
     case ('admin'): 
      redirect(site_url('admin/dashboard'), 'refresh'); 
     break; 
     case ('user'): 
      redirect(site_url('users/dashboard'), 'refresh'); 
     break; 
     case ('media'): 
      redirect(site_url('media-info/dashboard'), 'refresh'); 
     break; 
    } 

    ... 
} 
+0

那工作,但爲什麼你的案例字符串有括號?不需要:)另外,爲什麼設置刷新?沒有必要這樣做。 – 2011-01-02 03:40:25

+0

'refresh'是ion auth所使用的語法,所以如果沒有其他內容與主題一致。此外,根據CI文檔,'location'的默認重定向方法有時可能會成爲Windows服務器上的問題,所以理論上,如果您遇到其中一臺服務器,我認爲這種代碼更具可移植性。 – colonelclick 2013-07-26 03:29:08

0

這裏是我的,如果有人找使用功能,如果

function index() 
{ 
    if (!$this->ion_auth->logged_in()) 
    { 
     // redirect them to the login page 
     redirect('auth/login', 'refresh'); 
    } 
    else 
    { 
    if ($this->ion_auth->in_group('admin')) 
    { 
     echo "<h1>here is admin</h1>"; 
    } 
    else if ($this->ion_auth->in_group('user')) 
    { 
     echo "<h1>here is user</h1>"; 
    } 
    else if ($this->ion_auth->in_group('media')) 
    { 
     echo "<h1>here is media</h1>"; 
    } 
    else 
    { 
    echo "nothing happen" 
    } 
} 

希望它可以幫助一個人在那裏,

注意:確保組的相同組像上面