我是YII1
的新人。我有三个表:Jd
,jda
和user
。与jd
和jda
的关系是
'jobDescription'=> array(self::HAS_MANY, 'JobDescriptionAssignment', /*array('id'=>'job_desc_id')*/'id'),
并且jda
和user
之间的关系是
'users' => array(self::BELONGS_TO, 'User', 'user_id'),
我的表是:
jd-> ID,名称
jda->编号,jd_id,USER_ID
用户>编号,supervisor_id
supervisor_id
来自用户表ID。现在,我想显示jd
模型中supervisor_id
已登录ID的用户的数据。
答案 0 :(得分:1)
请参阅此主题Yii Framework : Join table (or other SQL) in data provider?
public function search(){
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('status',$this->status,true);
$criteria->compare('createDate',$this->createDate,true);
$criteria->compare('updateDate',$this->updateDate,true);
$criteria->compare('remark',$this->remark,true);
$criteria->with = array('cateLang' => array(
'condition' => 'cateLang.id = 1 OR cateLang.id = 2',
'order' => 'cateLang.id ASC'
));
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
-
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'category-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'id',
array(
'name' => 'FrenchTitle'
'value' => '(isset($data->cateLang[0])) ? $data->cateLang[0]->name : "no Title"',
),
array(
'name' => 'EnglishTitle'
'value' => '(isset($data->cateLang[1])) ? $data->cateLang[1]->name : "no Title"',
),
'createDate',
'updateDate',
'remark',
array(
'class'=>'CButtonColumn',
),
),
));