Yii findAllByAttributes with BETWEEN DATES AND ORDER BY

时间:2013-02-19 18:43:42

标签: php yii

我正在尝试按属性进行搜索,在给定的日期范围内按照创建的日期排序,但没有运气。

$user = array('user_country'=>1 ,'user_gender'='M');
    $rows = User::model()->findAllByAttributes($user,array("user_date_created BETWEEN '2012' AND '2013' " ,'order'=> 'user_date_created') );

提前谢谢。

2 个答案:

答案 0 :(得分:20)

必须使用CDbCriteria,如下所示:

$attribs = array('user_country'=>1 ,'user_gender'=>'M');
$criteria = new CDbCriteria(array('order'=>'user_date_created DESC','limit'=>10));
$criteria->addBetweenCondition('user_date_created', $date['date_start'], $date['date_end']);
$rows = user::model()->findAllByAttributes($attribs, $criteria);

希望将来有人帮助

答案 1 :(得分:4)

您可以使用:

$criteria = new CDbCriteria;
$criteria->condition = "date_start >= '$date_start' AND date_end <= '$date_end'";
$model = TemporadaAlta::model()->find($criteria);