Yii Framework Forum: Storing current CPagination page in session. - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Storing current CPagination page in session. Rate Topic: -----

#1 User is offline   WilsonC 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 47
  • Joined: 15-March 09

Posted 17 April 2009 - 11:27 AM

I'm currently trying to do the following:

I have a search form that stores POST data in submissions, so that the search listing remembers its "state" when i click into an individual item or another page, and then go back to the list again.

It works well for all the search parameters, but my list is paginated using CPagination component and ideally i would like to store the page in session as well.

Storing the actual value in the session(using $_SESSION and user->setState()) works as expected, but i'm having trouble setting the currentPage with the value from my session. Current code is shown as below:


Ps: I extended CPagination in the class Pagination to make the first page link have ?page=1 as compared to no "page" GET variable, so i can set the Session variable according to the GET variable.

Any ideas what i'm doing wrong anyone?
0

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,907
  • Joined: 04-October 08
  • Location:DC, USA

Posted 17 April 2009 - 12:01 PM

What is the problem?
0

#3 User is offline   WilsonC 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 47
  • Joined: 15-March 09

Posted 17 April 2009 - 12:09 PM

I want to store the full state of my search list in session, so if i leave the page and return, as long as the session is still alive, the list should be in the state i left it in e.g. same page, same search parameters etc.

Problem is that i can't get the current page to load from SESSION using the code i appended above. But all other parameters are ok.
0

#4 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,907
  • Joined: 04-October 08
  • Location:DC, USA

Posted 17 April 2009 - 12:27 PM

You are setting $_SESSION[__CLASS__][$pages->pageVar] all the time. You should not set it when you want to restore the current page from the session.
0

#5 User is offline   WilsonC 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 47
  • Joined: 15-March 09

Posted 17 April 2009 - 01:55 PM

I just realised also that i was setting the session variable to 1 all the time if there wasn't any GET page value in my example code.

How embarrassing haha...

It works now. Thanks!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users