如何在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 ");
答案 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);