tags:

views:

30

answers:

2

I have used Yii::app()->user->returnUrl but it always redirect me to localhost/index.php. Is there any particular configuration or some pieces of code that other programs that I must write? If you have another solutions let me know it.

A: 

I think, you must set it:

Yii::app()->user->setReturnUrl('controller/action');
addfs
But I don't know clearly the current url being accessed by the user.
aslingga
+1  A: 

@aslingga, can you please explain what you're trying to do with returnUrl? Are you just trying to get back to where you were after logging in, or are you using it somewhere else?

This is from the Yii documentation:

Redirects the user browser to the login page. Before the redirection, the current URL (if it's not an AJAX url) will be kept in returnUrl so that the user browser may be redirected back to the current page after successful login. Make sure you set loginUrl so that the user browser can be redirected to the specified login URL after calling this method. After calling this method, the current request processing will be terminated.

In other words, if the page you're trying to request requires authentication, the URI of the page you're on gets stored in a session variable. Then, once you've logged in, it takes you back to that page.

One way I'd recommend troubleshooting is to do a print_r($_SESSION); just to make sure the returnUrl is actually being stored. Then you'll be able to check if index.php is being stored as returnUrl or if you're just being redirected there for some reason.

Looking at the CWebUser methods getState and setState might also be helpful.

Philip Walton
I want to change my language from default EN_US to ID_ID. Like this url => http://www.domain.com/language/change/to/id_id. So after I change my language it will redirect to my last page. Do you have another solution? Let me know it.
aslingga
@aslingga, in response to your comment on @addfs' post. You can obtain the page the user is on via one of the CHttpRequest class methods. http://www.yiiframework.com/doc/api/1.1/CHttpRequest#url-detail. Which are wrappers for the php $_SERVER variable.
Philip Walton