从yii1中的三个表中收集数据?

时间:2015-06-07 07:08:39

标签: yii cactivedataprovider

我是YII1的新人。我有三个表:Jdjdauser。与jdjda的关系是

'jobDescription'=> array(self::HAS_MANY, 'JobDescriptionAssignment', /*array('id'=>'job_desc_id')*/'id'),    

并且jdauser之间的关系是

'users' => array(self::BELONGS_TO, 'User', 'user_id'),

我的表是:

  

jd-> ID,名称
    jda->编号,jd_id,USER_ID
    用户>编号,supervisor_id

supervisor_id来自用户表ID。现在,我想显示jd模型中supervisor_id已登录ID的用户的数据。

1 个答案:

答案 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',
        ),
    ),
));