Yii Framework Forum: how to change default return url for login action - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

how to change default return url for login action Rate Topic: -----

#1 User is offline   codesutra 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 596
  • Joined: 15-March 11
  • Location:India

Posted 08 May 2011 - 11:40 PM

hi every one ,

i am a bit confusing about a webuser return url in yii..

i want to redirect my all user on the default page like edit profile rather then index.php ..

i am using this syntex in my login action ..

$this->redirect(Yii::app()->user->returnUrl);

its working fine but the only issue is there i want to change a default return url..

all i want is that i want to redirect all user on their edit profile page when they login from sign up page..and return them on a same page from login required page..!!

i know that i have to just change a default return url..but dont know how to do it..!!! :(

i have already read this thread.
retun url is index.php

but couldn't get anything.that is why i start a new thread here.

anybody can rid me off from this problem.

thanks in advance..!!
CodeSutra
0

#2 User is offline   Shahzad Mirza 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 98
  • Joined: 07-February 11
  • Location:Pakistan

Posted 09 May 2011 - 12:35 AM

hi i had the same issue i used

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


to set the return url to user profile


and in the site controller actionLogin i used

if($model->validate() && $model->login()){

            if(end(explode('/',Yii::app()->user->returnUrl))=='index.php'){
		$this->redirect(array('user/profile','id'=>Yii::app()->user->id));
	    }else{
		 $this->redirect(Yii::app()->user->returnUrl);
	    }

}



this worked for me hope it will help you.
Don't be shy for asking Questions coz they might help u alot...
0

#3 User is offline   codesutra 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 596
  • Joined: 15-March 11
  • Location:India

Posted 09 May 2011 - 12:45 AM

View PostShahzad Mirza, on 09 May 2011 - 12:35 AM, said:

hi i had the same issue i used

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


to set the return url to user profile



would you please tell me where you add this piece of code..!! because it is not clear to me yet.

because i am getting this error after implementing you code..

error:-Only variables should be passed by reference

could you please tell me in which file i have to add this code..
CodeSutra
0

#4 User is offline   Shahzad Mirza 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 98
  • Joined: 07-February 11
  • Location:Pakistan

Posted 09 May 2011 - 01:01 AM

first i was using this on the controllers where i needed to set the return url such as when someone try to edit his profile with out login the in the update controller of profile i used this

 if(yii::app()->user->isGuest){
             Yii::app()->user->setReturnUrl('user/profile');
	     $this->redirect(array('site/login')); 
	   }else{
         // code  
}


but then i noticed that there is no need to set url in this case because the yii already sets the return url so i removed it but it worked for me on different controllers
Don't be shy for asking Questions coz they might help u alot...
0

#5 User is offline   Shahzad Mirza 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 98
  • Joined: 07-February 11
  • Location:Pakistan

Posted 09 May 2011 - 01:04 AM

View PostShahzad Mirza, on 09 May 2011 - 12:35 AM, said:

in the site controller actionLogin i used

if($model->validate() && $model->login()){

            if(end(explode('/',Yii::app()->user->returnUrl))=='index.php'){
		$this->redirect(array('user/profile','id'=>Yii::app()->user->id));
	    }else{
		 $this->redirect(Yii::app()->user->returnUrl);
	    }

}



this worked for me hope it will help you.


currently i m using this to redirecting to the users profile page by default when user is logged in

Note:
$this->redirect(array('user/profile','id'=>Yii::app()->user->id));

i m passing an id to the profile action to show that user profile
Don't be shy for asking Questions coz they might help u alot...
0

#6 User is offline   codesutra 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 596
  • Joined: 15-March 11
  • Location:India

Posted 09 May 2011 - 01:07 AM

thanks Shahzad ,

i've just added a condition in login action as mentioned by you and yes its work for me..

thank you again.!! :)
CodeSutra
0

#7 User is offline   Shahzad Mirza 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 98
  • Joined: 07-February 11
  • Location:Pakistan

Posted 09 May 2011 - 01:08 AM

you are welcome
Don't be shy for asking Questions coz they might help u alot...
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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