这是mysqli查询
SELECT DISTINCT t.company_id,t.image,t.text,t.date, t.title AS c_title
FROM news t
INNER JOIN companies c ON c.company_id=t.company_id ORDER BY t.date DESC
LIMIT 20" or die ("ERROR ". mysqli_error($link));
我想写CDbCriteria
$Criteria = new CDbCriteria();
$Criteria->join = 'INNER JOIN companies c ON t.company_id=c.company_id';
if ($place>0){
$Criteria->condition = "t.company_id = :place";
$Criteria->params = array(':place'=>$place);
}
$Criteria->order = "t.date DESC";
$Criteria->limit = 20;
$Criteria->select='t.company_id,t.image,t.text,t.date,c.title AS c_title';
$dataProvider = new CActiveDataProvider('News',
array(
'criteria'=>$Criteria,
'pagination'=>false
)
);
错误属性" News.c_title"未定义
答案 0 :(得分:1)
新闻模型中未定义属性c_title
(新闻表中的字段将自动作为属性提供,但c_title是标题的别名,而不是表格的字段)。
将其放入您的新闻模型中:
public $c_title;