Mohit Bhansali Mohit Bhansali - 3 months ago 17
PHP Question

Return To Last Url Entered After Successfull Login in YII

I have function login on its successful function control goes to

dashboard/index
, Suppose a user enter
leads/index
the page come back to login due to access rules defined, i just want that after successful login control goes to last url entered i.e.
leads/index
.

Thanks for your help.

Answer
... Controller extends CController (){
...
public function init() {

   if($this->isValidForRedirectRequest(Yii::app()->request)){
       Yii::app()->user->returnUrl = Yii::app()->request->requestUri;
   }
}
...

public function isValidForRedirectRequest(){
   /*something validations of request, like isAjax or other */
}
}...




... LoginController()...{

if($authIdentity->authenticate()) $this->redirect(Yii::app()->user->returnUrl);
...

}
Comments