2010-08-11 55 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" 
    } 
} 

希望它可以帮助一个人在那里,

注意:确保组的相同组像上面