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;

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

报告相同问题?

悬赏问题

  • ¥50 adb连接不到手机是怎么回事?
  • ¥15 vs2022无法联网
  • ¥15 TCP的客户端和服务器的互联
  • ¥15 VB.NET操作免驱摄像头
  • ¥15 笔记本上移动热点开关状态查询
  • ¥85 类鸟群Boids——仿真鸟群避障的相关问题
  • ¥15 CFEDEM自带算例错误,如何解决?
  • ¥15 有没有会使用flac3d软件的家人
  • ¥20 360摄像头无法解绑使用,请教解绑当前账号绑定问题,
  • ¥15 docker实践项目