returnUrl question?

Hi, just wondering if I need to set the return url to use Yii::app->user->returnUrl, or maybe some additional configuration in main.php? When I try to access Yii::app->user->returnUrl I am given the base url. For example, http://localhost/testdrive/index.php/ with out any controller/action or variables specified.

Hey all good I didn’t realize you have to set it. thought it may have been automatic. Worked with…


Yii::app()->user->setReturnUrl('controller/action');

what need to be done for redirecting a user to a different page other than default page after logging in??

Ver:1.1.6

Hi!

Try this one:


Yii::app()->user->returnUrl=array('controller/action');

Or override beforeLogin() in your CWebUser class


protected function beforeLogin(){

  //here could be your condition...

  $this->returnUrl=array('controller/action');

  return true;

}



For example you could submit together with Login and Password - Url or Variable and use it directly or as a condition for redirecting.




if($_POST['var']=='controller/action')$this->returnUrl=array('controller/action');


OR


if($_POST['var']!=1)$this->returnUrl=array('controller/action');



Do not forget validate() :)

This method is good when your login form is widget. Also you could create additional properties for the widget…

One last clarification is that return URL is only set when you request some page and it fails the authentication then after authentication it return backs to that page who causes failure.

If the browser is redirected to the login page and the login is successful, we may want to redirect the browser back to the page that caused the authorization failure. How do we know the URL for that page? We can get this information from the returnUrl property of the user component. We can thus do the following to perform the redirection:


Yii::app()->request->redirect(Yii::app()->user->returnUrl);