Yii findByAttributes() with greater than attribute. Yii findByAttributes() with greater than attribute. php php

Yii findByAttributes() with greater than attribute.


It's a good idea to use params even with findByAttributes, but that only does matching. You can use findAll and add a condition statement and the format would be very similar to what you are already doing:

$model=Auction::model()->findAll(array(    'condition'=>'status=:status AND starttime >= :date',    'params'=>array(':status'=>1, ':date'=>$date),));

If you were doing a very complex query or building a query programmatically you might want to use findAllBySql or CDbConnection::createCommand or Query Builder, it just depends on what makes the most sense for your app.

I would (re)read the Yii section on Working with Databases, while it doesn't have extensive examples, it's pretty clear. Then you can try the Yii Blog tutorial, Larry Ullman's tutorials, etc.


The type of the 2nd parameter of findAllByAttributes is mixed, thus we have (not infinitely but) many possibilities, for example:

$model = Auction::model()->findAllByAttributes(    array(      'status' => 1    ),     'starttime >= :date',     array(        'date'=>$date    )));

or

$model = Auction::model()->findAllByAttributes(    array(      'status' => 1    ),     array(      'condition' => 'starttime >= :date'      'params' => array('date'=>$date)    )));