Yii将管理员和经过身份验证的用户重定向到所需页面

Yii将管理员和经过身份验证的用户重定向到所需页面,yii,Yii,我是yii的新手。我希望我的管理员在从webapp/user/login登录时重定向到我想要的页面,即localhost/webapp/story,现在它正在将我重定向到index.php 我还注册了一个用户,并为该用户提供了一个经过身份验证的角色,我希望当我的用户(经过身份验证的用户)通过webapp/user/login登录时,该用户被重定向到index.php 所以有两件事: 1. redirecting admin to the desired page which is webapp/

我是yii的新手。我希望我的管理员在从webapp/user/login登录时重定向到我想要的页面,即localhost/webapp/story,现在它正在将我重定向到index.php

我还注册了一个用户,并为该用户提供了一个经过身份验证的角色,我希望当我的用户(经过身份验证的用户)通过webapp/user/login登录时,该用户被重定向到index.php

所以有两件事:

1. redirecting admin to the desired page which is webapp/story.
2. redirecting the authenticated user to index.php.
我正在使用yii用户和右扩展名。请帮我做这个。 代码登录控制器如下所示:

<?php

class LoginController extends Controller
{
    public $defaultAction = 'login';

    /**
     * Displays the login page
     */
    public function actionLogin()
    {
    if (Yii::app()->user->isGuest) {
        $model=new UserLogin;
        // collect user input data
        if(isset($_POST['UserLogin']))
        {
            $model->attributes=$_POST['UserLogin'];
            // validate user input and redirect to previous page if valid
            if($model->validate()) {
                $this->lastViset();
                if (Yii::app()->user->returnUrl=='/index.php')
                        $this->redirect(Yii::app()->controller->module->returnUrl);
                else// yehen par kuch aye ga according
                    $this->redirect(Yii::app()->user->returnUrl);
            }
        }
        // display the login form
        $this->render('/user/login',array('model'=>$model));
        } else
        $this->redirect(Yii::app()->controller->module->returnUrl);
     }

    private function lastViset() {
    $lastVisit =     User::model()->notsafe()->findByPk(Yii::app()->user->id);
    $lastVisit->lastvisit = time();
    $lastVisit->save();
    }

 }   

我想可能是这样的

<?php

class LoginController extends Controller
{
    public $defaultAction = 'login';

    /**
     * Displays the login page
     */
    public function actionLogin()
    {
    if (Yii::app()->user->isGuest) {
        $model=new UserLogin;
        // collect user input data
        if(isset($_POST['UserLogin']))
        {
            $model->attributes=$_POST['UserLogin'];
            // validate user input and redirect to previous page if valid
            if($model->validate()) {

                $this->lastViset();

                // Old code commentede
                //if (Yii::app()->user->returnUrl=='/index.php')
                //        $this->redirect(Yii::app()->controller->module->returnUrl);
                //else// yehen par kuch aye ga according
                //    $this->redirect(Yii::app()->user->returnUrl);

                // new code
                if (UserModule::isAdmin()){
                    $this->redirect(array('story/index'));
                }  
                else  {
                    $this->redirect(Yii::app()->user->returnUrl);   
                }  


            }
        }
        // display the login form
        $this->render('/user/login',array('model'=>$model));
        } else
        $this->redirect(Yii::app()->controller->module->returnUrl);
     }

    private function lastViset() {
    $lastVisit =     User::model()->notsafe()->findByPk(Yii::app()->user->id);
    $lastVisit->lastvisit = time();
    $lastVisit->save();
    }

 }   

我真的很感激,但是我在问题中提到了错误的url,对此我很抱歉。正确的url是“webapp/user/login”。我认为用户扩展中的LoginController.php将进行更改。我已经更新了这个问题。。请看上面的代码,我也更新了问题。。。!!你现在显示的代码就是你想要修改的代码?是的,伙计,我的一个朋友告诉我,你必须在那里修改你想要的东西。谢谢伙计,我会检查。。。实际上,我要做的工作是获取注册用户的角色。比如,如果用户是admin,那么在登录时,admin应该会看到sidebarwidget,因为我已经创建了sidebarwidget,如果用户(经过身份验证)登录了,那么只需看到index.php。。!!我希望你能理解。请看一下这个。