views:

74

answers:

1

I've set up a page that displays server logs and added a filter form so I can filter the logs on specific actions, dates, etc. I can't seem to figure out how to use CPagination to split the results into pages, however. If I add the CPagination widget, when a page is selected from the widget, the filter form isn't resubmitted and my filter results are lost.

I'm at a loss for a simple solution to maintain my filter form data with the CPagination widget. Any suggestions would be great.

Update
I have this functioning but I had to set a session state to maintain my form data.

$filter=false;
$form=new LogFilterForm;
if(isset($_POST['LogFilterForm'])){
    $form->attributes=$_POST['LogFilterForm'];
    Yii::app()->user->setState('filter',$form);
    $filter=true;
}
else if(Yii::app()->user->hasState('filter')){
    $form=Yii::app()->user->getState('filter');
    $filter=true;
}

Any ideas on how I can clear the session state on navigation to another page?

+1  A: 

If you were using CGridView it would be easy to add filters with paging - it's built in. Just look at the admin.php view rendered by the Gii crud tool (or the blog demo maybe too). Perhaps you don't want to display the logs in table form though.

Instead of setting session variables you could make the form a stateful form and save the previous state using setPageState(). I don't know if the pagination submits the form though... you might have to bind a jQuery event to submit the form when clicking on the pagination links. That would be kinda ugly if you had to do that.

As for clearing the session state variables, my only idea right now is to override onBeginRequest() or something to check if the user is on the search page, and if they aren't, then clear the session variable. You could just leave it too - set a short expiration date and forget it. Or save it to your database instead of the session? :P

EDIT

If you go the route of overriding onBeginRequest() it looks like it's as easy as declaring a callback in the config file. More info here in the Yii forums, and here too. I've never actually done it myself though. Good luck!

thaddeusmt
Sadly I'm stuck using 1.0 (I started the project months ago). As far as I can tell CGridView is new to 1.1. I'm thinking overriding onBeginRequest() is my best bet. Where should I place my derived class and how would I set up config to use it rather than the normal application class?
Jason George
added a couple of forum links that should help out
thaddeusmt
Finally getting back to this. Overriding onBeginRequest() was insanely easy. Thanks for pointing me right to the references.
Jason George