yii CDbCriteria选择不工作?

时间:2014-12-19 12:06:09

标签: php yii cgridview cactivedataprovider

我需要编辑CGridView的查询

所以在我的模型中我改变了函数search(),如下所示:

$criteria=new CDbCriteria;
$criteria->select = "links.title, links.url, groups.title as grouptitle";
$criteria->join = " join groups on links.id_group = groups.id_group";
$criteria->addCondition("links.id_user = '" . Yii::app()->user->getId() . "'");

return new CActiveDataProvider($this, array(
    'criteria'=>$criteria,
));

但是从我的观点来看,我收到一条错误,告诉我选择不正确:

The SQL statement executed was: SELECT COUNT(*) FROM `links` `t` join groups on links.id_group = groups.id_group WHERE links.id_user = '1'

为什么呢?

1 个答案:

答案 0 :(得分:1)

除非明确设置,否则默认table aliast。您可以通过以下方式执行此操作:

$criteria->alias = 'links';