[EXTENSION] XReturnable (was:Ideas for storage of click path / visited pages)

Thanks for the comments


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


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

Will you release it as an extension?

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

I've refactored the code and created an extension now. You can download it here:


It also includes a little demo.


  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"



  thanking you,

  but where i put this command Yii::require("application.extensions.XReturnable")

Please don't open so many topics for the same question. I've counted 3 now…

To your problem: add this to the import section of your configuration:







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




            $route=isset($_GET[$r]) ? $_GET[$r] : $c->getId().'/'.$c->getAction()->getId();




        return $this->_currentPageParams;




Attached is the updated XReturnable.




Cool, thanks. I’ll update the extension soon.

Actually i knew about the problem with arrays but had no time to think about a fix. Nice to see this solved now. :)

Extension is updated now with the provided fix (slightly simplified it).

You can also configure the GET variable name for the stack now with paramName.

include(XReturnable.php) [<a href=‘function.include’>function.include</a>]: failed to open stream: No such file or directory

Where do you get this? How did you include it?

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.