在Nginx服务器上使用Yii returnUrl [英] Using Yii returnUrl on nginx server

查看:126
本文介绍了在Nginx服务器上使用Yii returnUrl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有Yii应用程序的nginx服务器.

I'm using nginx server with Yii application.

我的问题是,成功登录后重定向我的SiteController.php中的Yii::app()->user->returnUrl值始终是-mysite/index.php,无论我来自哪个页面.

My problem is that the value of Yii::app()->user->returnUrl , in my SiteController.php , which redirect me after a successful login is always - mysite/index.php , regardless of which page I came from.

如何将其固定为上一页URL的值?

How can i fix it to be the value of the previous page URL ?

推荐答案

这是您看到的默认行为,如果要更改,可以选择一些方法!这些选择的同一部分是您应该扩展CWebUser并添加功能

That's the default behavior you are seeing, if you want to change that there are some choices! The same part in these choices is that you should extend CWebUser and add the functionalities

class WebUser extends CWebUser
{
}

&您需要在配置中提及它

& you need and mention it in the config

'user'=>array(
    'class' => 'WebUser',
    'loginUrl' => array('user/login'),
    'defaultDashboard' => array('user/dashboard'),
)

完成,现在选择!如果您要的returnUrl已固定,请在登录前的函数中设置此函数,则应在WebUser类中覆盖此函数并手动设置returnUrl,有关更多信息,请参见

done, now the choices! if the returnUrl you want is fixed set it in function beforeLogin, you should override this function in the WebUser class and set the returnUrl manually, more info at Official API for CWebUser. But if returnUrl is not fixed & you want it to be set almost for every action which needs login then you should override the loginRequired function

public function loginRequired() {
    $app=Yii::app();
    $request=$app->getRequest();
    $controller=$app->controller;
    $actionParameters=$controller->actionParams;

    if(!$request->getIsAjaxRequest()) {
        if(empty($actionParameters))
            $this->setReturnUrl(array($controller->route));
        else
            $this->setReturnUrl(array($controller->route,$actionParameters));
    }
    if(($url=$this->loginUrl)!==null) {
        if(is_array($url)) {
            $route=isset($url[0]) ? $url[0] : $app->defaultController;
            $url=$app->createUrl($route,array_splice($url,1));
        }
        $request->redirect($url);
    }
    else
        throw new CHttpException(403,Yii::t('yii','Login Required'));
}

&成功登录后的最后一步,防止循环

& the last step prevent loop after successful login

if($model->validate() && $model->login()){
    $returnUrl=Yii::app()->user->returnUrl;
    $url=(is_array($returnUrl))?$returnUrl[0]:$returnUrl;
    if(isset($returnUrl)&&stripos(strtolower($url),'logout')==false&&stripos(strtolower($url),'login')==false) {
        $this->redirect($this->createUrl($returnUrl[0],$returnUrl[1]));
    } else {
        $this->redirect($this->createUrl($returnUrl[0],$returnUrl[1]));
    }

这篇关于在Nginx服务器上使用Yii returnUrl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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