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

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

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

#21 User is offline   kartom 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 25-February 09
  • Location:Sweden

Posted 29 March 2009 - 03:43 PM

Thanks for the comments

Quote

- 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.  ;)
Will you release it as an extension?
0

#22 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 30 March 2009 - 02:57 AM

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

0

#23 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 08 June 2009 - 02:44 AM

I've refactored the code and created an extension now. You can download it here:
http://www.yiiframew...on/xreturnable/

It also includes a little demo.
0

#24 User is offline   velsa 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 21-June 09
  • Location:canada,US

Posted 24 June 2009 - 10:54 AM

hi
  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"
0

#25 User is offline   olafure 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 04-March 09
  • Location:Iceland

Posted 24 June 2009 - 11:08 AM

Yii::require("application.extensions.XReturnable")
0

#26 User is offline   velsa 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 21-June 09
  • Location:canada,US

Posted 24 June 2009 - 11:15 AM

hi,
  thanking you,
  but where i put this command Yii::require("application.extensions.XReturnable")
0

#27 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 24 June 2009 - 11:20 AM

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:

<?php
    'import'=>array(
        'application.models.*',
        'application.components.*',
        'application.extensions.xreturnable.*',
    ),





0

#28 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 13 July 2009 - 06:26 AM

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

#29 User is offline   SilentWarrior 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 29-July 09

Posted 30 July 2009 - 07:57 PM

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

#30 User is offline   M├írcio 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 28-July 09
  • Location:Bra(s|z)il

Posted 04 November 2009 - 05:18 PM

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...lope][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;
    }

...

}


Attached is the updated XReturnable.

Attached File  XReturnable.php (7.62K)
Number of downloads: 2

Thanks
1

#31 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 05 November 2009 - 04:03 AM

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. :)
0

#32 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 11 November 2009 - 07:36 AM

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

#33 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 873
  • Joined: 20-April 11
  • Location:India

Posted 11 January 2012 - 07:42 AM

include(XReturnable.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#34 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 11 January 2012 - 11:46 AM

View PostRajith R, on 11 January 2012 - 07:42 AM, said:

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

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • 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