我想在Yii框架中将此SQL查询转换为CDbCriteria格式,以便我可以在Yii中使用它:
SELECT title FROM project WHERE ((title like 'to %') or (title like ' % to %') or (title like '% to'));
Yiiframework CDbCriteria描述链接如下:
答案 0 :(得分:4)
你也可以尝试这个
$criteria = new CDbCriteria;
$criteria->select = "title";
$criteria->compare('title',' to ',true);
$model = new Project;
$models = $model->findAll($criteria);
答案 1 :(得分:2)
你走了:
$criteria = new CDbCriteria;
$criteria->select = "title";
$criteria->condition = "((title like ':to%') or (title like ' % :to %') or (title like '% :to'))";
$criteria->params = array(':to' => 'to');
$model = new Project;
$models = $model->findAll($criteria);