Monday, August 8, 2011

Yii CActiveDataProvider and a Limit Condition

Just discovered that, if you're trying to limit the number of results in a query using "limit" in your CActiveDataProvider configuration, you need to explicitly include 'pagination'=>false for it to work. For example:


$fCriteria = new CDbCriteria;
$fCriteria->with = array('textualContent','entity');
$fCriteria->limit = 2;



$fashionFindsDataProvider = new CActiveDataProvider('FashionFinds',
array(
'criteria'=>$fCriteria,
'pagination'=>false,
)
);

If you don't, limit does not take effect. Note that I'm using a CDbCriteria object, but you could also do this:


$fashionFindsDataProvider = new CActiveDataProvider('FashionFinds', 
array(
'criteria'=>array('limit'=>2), // Leaving out the other junk from above for easy reading
'pagination'=>false,
)
);



No comments:

Post a Comment