Yii Framework Forum: returnUrl question? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

returnUrl question? Rate Topic: -----

#1 User is offline   fibler 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 06-October 09

Posted 30 October 2009 - 10:25 AM

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.
1

#2 User is offline   fibler 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 06-October 09

Posted 30 October 2009 - 11:53 AM

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

1

#3 User is offline   sravani 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 48
  • Joined: 22-January 11

Posted 02 February 2011 - 08:42 AM

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

#4 User is offline   Jay_69 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 51
  • Joined: 27-August 10

Posted 07 February 2011 - 09:20 AM

 sravani, on 02 February 2011 - 08:42 AM, said:

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...
3

#5 User is offline   rahul.vit09 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 48
  • Joined: 07-February 11

Posted 12 February 2011 - 10:15 PM

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

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users