Hi,
Trying to apply a filter to a ListView but pagination returns incorrect results - should be 12 items/page.
[center]----------------------------[/center][center]Product [/center][center] Id [/center][center]----------------------------[/center][center] |[/center][center] |[/center][center] |[/center][center] *[/center][center]----------------------------[/center][center]ProductAudience [/center][center] product_id [/center][center] audience_id [/center][center]----------------------------[/center][center] *[/center][center] |[/center][center] |[/center][center] |[/center][center]----------------------------[/center][center]Audience [/center][center] id [/center][center]----------------------------[/center]
Product
public function relations()
{
return array(
'audiences' => array(self::MANY_MANY, 'Audience', '{{product_audience}}(product_id, audience_id)'),
....
);
}
ProductController
public function actionIndex(array $audience = array())
{
$criteria = new CDbCriteria();
$criteria->order = 't.name';
if (count($audience) > 0)
{
$criteria->with = array('audiences');
$criteria->together = true;
$criteria->addInCondition('audiences.id', $audience);
}
$dataProvider = new CActiveDataProvider('Product', array(
'criteria' => $criteria,
'pagination' => array(
'pageSize' => 12,
)
));
$this->render('index', array(
'dataProvider' => $dataProvider
));
}
Try it out here - http://cakecravings…skelton.ca/shop - select a few categories and you’ll notice the number of items decreases with each Filter added. If ALL filters are added, a page only has 3 items/page.
Thanks!