Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Many-Many Filter

$
0
0
Hi,

Trying to apply a filter to a ListView but pagination returns incorrect results - should be 12 items/page.
----------------------------Product Id ---------------------------- | | | *----------------------------ProductAudience product_id audience_id ---------------------------- * | | |----------------------------Audience id ----------------------------
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!

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>