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;

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

报告相同问题?

悬赏问题

  • ¥15 求MCSCANX 帮助
  • ¥15 机器学习训练相关模型
  • ¥15 Todesk 远程写代码 anaconda jupyter python3
  • ¥15 我的R语言提示去除连锁不平衡时clump_data报错,图片以下所示,卡了好几天了,苦恼不知道如何解决,有人帮我看看怎么解决吗?
  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开