zii.widgets.CListView 的关联查询问题 [ 新手入门 ]
控制器层的语句:
system.db.CDbCommand.query(SELECT t.*,oa_department.name as bname FROM
oa_staff
t left join oa_department ON t.department=oa_department.id ORDER BY id DESC LIMIT 10)
视图:
<b><?php echo CHtml::encode($data->getAttributeLabel('department')); ?>:</b>
<?php
echo CHtml::encode($data->bname); ?>
<br />
报错:Property "Staff.bname" is not defined
求高手指点
共 6 条回复
-
public function actionIndex() { $criteria=new CDbCriteria; $criteria->select="t.*,oa_department.name as bname"; //$criteria->condition="id=:id"; //$criteria->params+=array(':id'=>5);//查询条件 $criteria->join="left join oa_department ON t.department=oa_department.id"; $criteria->order='id DESC'; $dataProvider=new CActiveDataProvider('Staff',array( 'criteria'=>$criteria, ) ); $this->render('index',array( 'dataProvider'=>$dataProvider, )); }
这是我构造的sql语句 我上面的语句是从这里出来的 不知道问题在哪里
dapeng
注册时间:2012-08-12
最后登录:2014-07-26
在线时长:0小时20分
最后登录:2014-07-26
在线时长:0小时20分
- 粉丝2
- 金钱1160
- 威望0
- 积分1160