Reuse Cdbcommand Created


I want to have a product listing method in my controller that may receive 0-4 params (what i call ‘filters’).

And I want to have pagination, so I also have to make a query of ‘count(*)’.

What i really want to do is to construct the query once, checking for the existence of params and adding ‘ANDWHERE’ clauses,

and when I want to get the information, I want to reuse the query already built, and just change the ‘SELECT’ clause.

I tried to construct and execute the count(*) query, and then just do


$dataProvider = new CSqlDataProvider( $cmd, array(



                'pageSize' => 24,




But it creates the select count(*) query again…

Any thoughts?