Dear Friend
This is something to share with you on this topic.
CWebUser has no property declared as returnUrl.
When we are going to set this property in main configuration file,it is going to invoke the
method CWebUser::setReturnUrl.
public function setReturnUrl($value)
{
$this->setState('__returnUrl',$value);
}
This method instead of assigning the value to returnUrl, it is storing the value in session.
My fear :
When application configures the components by reading the main configuration file, Does the uninitialised state of other components or a component in question affect the creation of that particular component?.In our case when the component user is crearted, is the component session available to configure the user?.
situation 1; This works…
main.php
'components'=>array(
'user'=>array(
'class'=>'application.components.webUser',
'allowAutoLogin'=>true,
'returnUrl'=>'index.php?r=site/contact',
),
webUser.php in components folder.
<?php
class webUser extends CWebUser
{
public $returnUrl;
}
situation 2: This works… without the property returnUrl
'components'=>array(
'user'=>array(
'class'=>'application.components.webUser',
'allowAutoLogin'=>true,
'returnUrl'=>'index.php?r=site/contact',
),
webUser.php in components folder.
class webUser extends CWebUser
{
//public $returnUrl;
public function getReturnUrl($defaultUrl=null)
{
return $this->returnUrl;
}
public function setReturnUrl($url)
{
$this->returnUrl=$url;
}
}
situation 3: It works…
Instead of declaring the defaultUrl in main.php, if we declare it down the lane, it works.
Here I am declaring it in a behavior attached to main application without extending the CWebUser.
Main.php
..............................
'behaviors'=>array(
'class'=>'application.components.applicationBehavior',
),
..............................
'components'=>array
'user'=>array(
'allowAutoLogin'=>true,
),
applicationBehavior in components folder.
<?php
class applicationBehavior extends CBehavior
{
private $_owner;
public function events()
{
return array(
'onBeginRequest'=>'assignReturnUrl',
);
}
public function assignReturnUrl()
{
$owner=$this->_owner=$this->getOwner();
$owner->user->returnUrl='index.php/?r=site/contact';
}
}
?>
All these results compound my fear that the problem arises when components are created and initialized.
I need your inputs on this.
As suggested by bennouna, I was trying to get ‘HTTP_REFERER’ from CHttpRequest::getUrlReferrer to get
returnUrl.It is always bringing null in my localhost in all the browsers.
I tried to catch the the last two requests and put them in session. So when user jumps from one particular page into login page, after successful login he again redireced to that particular page.
applicationBehavior.php in components folder.
<?php
class applicationBehavior extends CBehavior
{
private $_owner;
public function events()
{
return array(
'onBeginRequest'=>'assignReturnUrl',
);
}
public function assignReturnUrl()
{
$owner=$this->_owner=$this->getOwner();
if($owner->session->contains('pastUrl'))
$owner->user->returnUrl=$owner->session->get('pastUrl');
if($owner->session->contains('currentUrl'))
$owner->session->add('pastUrl',$owner->session->get('currentUrl'));
$owner->session->add('currentUrl',$owner->request->url);
}
}
?>
The issue needs further clarification.
Regards.