yii:登录后如何重定向到不同的页面? [英] yii : how to redirect to different page after logged in?

查看:33
本文介绍了yii:登录后如何重定向到不同的页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问:登录后如何重定向到不同的页面?

Q : how to redirect to different page after logged in?

状态:我有自定义用户角色,我想为不同的用户重定向到不同的页面.

status : I've custom user role and I want to redirect to different page for different user.

例如人力资源经理 -> 员工/索引,客户经理 -> 帐户/索引.

e.g hr manager -> employee/index, account manager -> account/index.

我使用的是 yii 1.1.xx 和权限模块.yii 和权限模块绿色.

I'm using yii 1.1.xx and rights module. yii and rights module are going with green.

更新问题信息

这是排名tbl

这是用户 tbl

如果等级是客户经理,网站将重定向到账户/索引.

If the rank is Account Manager, the web site will redirect to account/index.

如果职级是人力资源经理,网站将重定向到员工/索引.

If the rank is HR manager, the web site will redirect to employee/index.

推荐答案

if(Yii::app()->user->checkAccess('hrManager',Yii::app()->user->getId())==1)
{
    $this->redirect(array("employee/index"));
} else if(Yii::app()->user->checkAccess('accountManager',Yii::app()->user->getId())==1) {
    $this->redirect(array("account/index"));
}

其中hrManageraccountManager 是HR Manager 和Account Manager 登录对应的访问规则.这将检查用户是否具有人力资源经理"级别的访问权限,如果是,则将他们重定向到那里,然后检查用户是否具有客户经理"级别的访问权限,如果是,则将他们重定向到该页面.

Where hrManager and accountManager are the corresponding access rules for the HR Manager and Account Manager logins. This will check to see if the user has 'HR Manager' level access, if so redirect them there, and then checks if the user has 'Account Manager' level access, if so redirects them to that page.

显然,您可以自定义它如何适合您的应用,因为如果用户既没有 HR Manager 也没有 Account Manager 访问权限,上面的代码就不会重定向到任何地方,因此您需要另一个捕获器.

Obviously you can customise to how it suits your app, as the above code won't redirect anywhere if the user has neither HR Manager or Account Manager access, so you'll need another catcher.

hrManager 字符串是 rbac authitem 名称,你有表 authassignmentauthitemauthitemchild 为您的 rbac 设置了吗?

The hrManager string is the rbac authitem name, do you have tables authassignment authitem and authitemchild set up for your rbac?

如果没有,您可以使用排名表以稍微不同的方式使用此方法.您可以使用 rank_id 进行设置,但您必须加载用户模型(如果您尚未加载它),这可能不是最有效的方法.

If not, you can use this method a little differently using your ranking table. you can either set it up using the rank_id, but you'd have to load the user model (if you haven't already got it loaded) which might not be the most efficient way of doing it.

$user = User::model()->findbyPk(Yii::app()->user->getId());
if($user->rank_id==3)
{
    $this->redirect(array("employee/index"));
} else if($user->rank_id==2)) {
    $this->redirect(array("account/index"));
}

另一种方法是在登录后将用户排名加载到 Yii::app()->user 参数中,这样您就不必在重定向之前加载用户模型,也许您已经为但是您授予对页面的访问权限?

The other way would be to load the users rank into the Yii::app()->user param after login so you don't have to load the user model before the redirect, maybe you have this set up already for however you are granting access to pages?

if(Yii::app()->user->rank_id==3)
{
    $this->redirect(array("employee/index"));
} else if(Yii::app()->user->rank_id==2)) {
    $this->redirect(array("account/index"));
}

这篇关于yii:登录后如何重定向到不同的页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆