2016-04-25 63 views
0

花了這麼多天後,我試圖從專家那裏得到一些幫助。 我堅持登錄重定向只在Chrome瀏覽器中我yii2應用,yii2登錄頁面重定向循環取消狀態

enter image description here

這是我的控制器類,

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); 
       } 


    } 
} 

我的工作流程 第一步:提交FORMDATA到控制器XX-行動 第2步:如果用戶登錄它將繼續進一步操作 否則 正試圖存儲會話中的值,然後重定向頁面登錄

第3步:登錄成功後,上午返回到相同的XX-行動

這個工作流程在Firefox工作正常,但鉻它使不定式環路它不是通過登錄頁。 請參考我附的截圖

請幫我解決這個問題。

回答

1

我不能infere你怎麼呼喚你actionGenerateevent()但你似乎已經出現的錯誤:

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

既然你不設置你的$redirectUrl,你redirect您重定向到目前(相同)網址一遍又一遍,導致循環。

這是redirectUrl()方法使用的功能:Url::to()。它的文檔說:

一個空字符串:當前請求的URL將被返回;

+0

實際上我在這裏調用beforeaction()函數,所以不需要$ redirectUrl =「」。 順便說一下,你是正確的,首先點擊actionGenerateevent()有問題,因爲我在這個動作中提交表單,出現這個問題。現在我修好了。非常感謝。 – user3535066

+0

@ user3535066我很高興幫助!你能標記我的答案嗎?感謝名單 – slinstj