- You override CController, which means, it's not so easy to integrate
I realize that user store its states as session, but i haven’t thought about the problem with the same application opened in several tabs (but i guess it is a standard problem when working with session ). I can’t see no easy way, if any, to solve this problem.
Quote
- As stated before, session (and state is nothing else) isn't optimal, as users might have the same application open in 2 browser tabs. One tab might overwrite returnUrl from the other tab, which gives unexpected results.
Overriding CController was not a problem in my special case, but i guess makes it difficult to create an extension of it. Or at least it will be difficult to use it together with other extensions that also overrides CController.
These 2 drawbacks, especially the first one, are much worse than having the url cluttered so i think i will go with Mike’s solution.
Not sure if it’s ready for release as an extension yet. Maybe we can make it more flexible (e.g. make storage in GET or SESSION configurable). I also want to think about easier API first. Usage should be intuitive to understand and i doubt it already is.
How to install XReturnable. i downloaded and exctract archive file and place folder into protected/extension. but its not working. if i run means i have an error.
this is error
"YiiBase::require(XReturnable.php) [<a href='yiibase.require'>yiibase.require</a>]: failed to open stream: No such file or directory"
Thanks to robak for finding a bug with url path format. I've changed the urlCompress/urlUncompress methods now and also removed the addslashes() there.
I have applied this successfully to forms such as LoginForms, with a hidden field named "referer" that would be set using the referer of the last known page when a login form was presented.
Why? Because it would “stick” and not be overridden using if(!isset($_POST[‘referer’]).
If user typed wrong password and the page would be refreshed, it would wipe out the initial referer, so it would go back to the login form itself.
If user had multiple windows, session wouldnt work.
Maybe, using this system, but, with a diferent variable, so it works without forms too.
I have found a bug in XReturnable, but I fixed it already. Read the comments in the second method.
class XReturnable extends CBehavior
{
...
private static function convertFromTreeToKeyValue($tree,
$keyPrefix = '')
{
$resp = array();
foreach($tree as $k => $v) {
$newKey = $k;
if(!empty($keyPrefix)) {
$newKey = $keyPrefix.'['.$k.']';
}
if(is_array($v)) {
$tmp = self::convertFromTreeToKeyValue($v, $newKey);
$resp = array_merge($tmp, $resp);
} else {
$resp[$newKey] = $v;
}
}
return $resp;
}
/**
* @return array the current page parameters with route as first entry
*/
protected function getCurrentPageParams()
{
if ($this->_currentPageParams===null) {
// $_GET variable can contain the folowing value:
// array( // (1)
// 'Message' => array(
// 'envelope'=> array(
// 'uid'=>1932
// )
// )
//);
// We will get this when form inputs or GET variables have names like
// <input name="Message[envelope][uid]" value="1932" /> or
// GET parameters like http://abc.def/index.php?Message[envelope][uid]=1932 (2)
// It is necessary to convert it back to key=>values without internal arrays
// that is, convert from layout (1) to (2)
// (1) is made by the browser from (2)
$keyValue = self::convertFromTreeToKeyValue($_GET);
$this->_currentPageParams=$keyValue;
$r=Yii::app()->urlManager->routeVar;
$c=$this->getOwner();
$route=isset($_GET[$r]) ? $_GET[$r] : $c->getId().'/'.$c->getAction()->getId();
unset($this->_currentPageParams[$r]);
array_unshift($this->_currentPageParams,$route);
}
return $this->_currentPageParams;
}
...
}
Actually this is a pretty old extension which i wrote more as a proof of concept. I’ve never used it. But if you really need it, i can try to update it.