Limiting results for CGridView

Hi All,

I’m building a ticket system for a client.

Each ticket has 3 statuses pending, processing and complete.

I’ve been trying to figure out how to create a view(with CGridView) to show only pending and processing tickets.

I can set $model->status = ‘<>complete’ but i want to be able to search/filter the resulting pending/processing tickets.

I’ve found ‘condition’ in my model’s search function can do the limiting but it does it for all views, i’m trying to get a limit for just this view.

I’ve also seen findAllByAttributes which could work, but it’s more work to get all the search/filter functionality up and running

Is there any way in my controller to limit/pre-filter results?

Thanks

Oliver

i would do, in controller


if (!isset($_GET['Ticket']))

    //initial filter here - pending and processing tickets;

else 

    //no filter - regular search



Have you checked this?

http://www.yiiframework.com/doc/guide/1.1/en/database.ar#named-scopes

@rootbear I would like to do it in the controller, Can you apply filters that will not show in the grid’s filter text boxes.

@wisp That looks very usefull. Any idea how i would implement it in my controller? this is my action funcition (for CGridView):




public function actionOpen(){

	$model=new Ticket('search');

	$model->unsetAttributes();  // clear any default values

	if(isset($_GET['Ticket']))

		$model->attributes=$_GET['Ticket'];


	$this->render('index',array(

		'model'=>$model,

	));

}



Thanks for your responses

Oliver

I’ve just written an article about this: http://blog.4aal.nl/post/yii-named-scopes-examples

thanks a lot @wisp, very helpful

Nice to hear, I’ll write some more articles if people are interested…