I use findAll() like this:
$l = SiteContentRelated::model()->findAll('content_1=:c', array(':c' => $id));
How I can add condition to this?
Like as LIMIT 5
or anything?
Use CDbCriteria
to specify more detailed criteria:
$criteria = new CDbCriteria;
$criteria->condition = 'content_1=:c';
$criteria->limit = 5;
$criteria->params = array(':c' => $id);
$l = SiteContentRelated::model()->findAll($criteria);
or pass an array to findAll
which will be converted to a CDbCriteria
:
$l = SiteContentRelated::model()->findAll(array(
'condition' => 'content_1=:c',
'limit' => 5,
'params' => array(':c' => $id),
));
When you specify a LIMIT
, it's a good idea to also specify ORDER BY
.
For filtering based on model attributes, you can also use findAllByAttributes
:
$l = SiteContentRelated::model()->findAllByAttributes(array(
'content_1' => $id,
), array(
'limit' => 5,
));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With