dsff788655567 2016-04-25 06:50
浏览 119
已采纳

yii2登录页面重定向循环,取消状态

After spending so many days, am trying to get some help from experts. I am stuck with login redirection in my yii2 application only in chrome browser,

enter image description here

This is my controller class,

    class InvitationsController extends Controller
{
    public function beforeAction($action)
    {   $array=array('index','imageupload','template','category','subcategory','slug','chooseanotherdesign');
        if(!in_array($action->id, $array))
           {
                if (\Yii::$app->getUser()->isGuest &&
                    \Yii::$app->getRequest()->url !== Url::to(\Yii::$app->getUser()->loginUrl)
                ) {
                    \Yii::$app->getResponse()->redirect(\Yii::$app->getUser()->loginUrl,FALSE);
                }
           }
                return parent::beforeAction($action);
    }
    public function actionGenerateevent(){
        $redirectUrl="";
                if(Yii::$app->request->post()){
                    unset(Yii::$app->session['copyinvitation']);
                    unset(Yii::$app->session['eventform']);
                    Yii::$app->session['eventform']=Yii::$app->request->post();
                }
                if (!Yii::$app->user->isGuest)
                {
                        $eventid=$this->invitation->savecontinue(Yii::$app->session['eventform']);
                        $eventdata=$this->invitation->getEventById($eventid);
                        $refurl=Yii::$app->session['eventform']['refererurl'];
                        $aa['Events']=$eventdata;
                        $aa['refererurl']=$refurl;
                        Yii::$app->session['eventform']=$aa;
                        $redirectUrl = Yii::$app->urlManager->createAbsoluteUrl(['invitations/event/'.$eventdata['event_token']]);
                        return $this->redirect($redirectUrl);
                }


    }
}

My workflow step1: submitting formdata to controller xx-action step2: If user login it will proceed further action Else am trying to store the values in session then redirecting the page to login

step 3: after successful login am return back to same xx-action

This workflow is working fine in firefox but chrome it's making infinitive loop its not going through the login page. Please refer am attached the screenshot

Please help me to solve this issue.

  • 写回答

1条回答 默认 最新

  • doumouyi4039 2016-04-27 02:11
    关注

    I can't infere how are you calling your actionGenerateevent() but you seems to have an error there:

    $redirectUrl=""; //empty
    ...
    return $this->redirect($redirectUrl); //still empty
    

    Since you are not setting your $redirectUrl, your redirect is redirecting you to the current (same) url again and again, causing the loop.

    This is the function used by redirectUrl() method: Url::to(). Its docs says:

    an empty string: the currently requested URL will be returned;

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 matlab解优化问题代码
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp
  • ¥15 学不会递归,理解不了汉诺塔参数变化
  • ¥15 基于图神经网络的COVID-19药物筛选研究
  • ¥30 软件自定义无线电该怎样使用
  • ¥15 R语言mediation包做中介分析,直接效应和间接效应都很小,为什么?
  • ¥15 Jenkins+k8s部署slave节点offline