CDb标准条件

时间:2015-08-03 05:02:53

标签: php yii

如何在CDbcriteria中创建以下SQL条件

$dbCommand = Yii::app()->db->createCommand("SELECT * FROM offer_events WHERE enddate >= '$now' AND title like '%$locationdet%' AND description like '%$locationdet%' ORDER BY id DESC ");

1 个答案:

答案 0 :(得分:1)

您可以尝试:

$criteria = new CDbCriteria();
$criteria->condition = 'enddate >=:enddate AND title LIKE :title AND description LIKE :description';
$criteria->params = array(
    ':enddate'=>$enddate, 
    ':title'=> '%' . $title . '%', 
    ':description' => '%' . $description .'%'
);
$criteria->order = 'id DESC';
$model = SomeModel::model()->find($criteria);