如何在数据提供者的条件下使用findall的结果?

时间:2014-04-11 12:35:10

标签: yii

我想在cactivedataprovider的条件下使用findall的结果吗?

 $criteria->condition = 'department_id=:email';
    $criteria->params = array(':email'=>$id);
    $subject_ids=subject::model()->findAll($criteria);

public function myDataProvider($subject_ids)
{

    foreach($subject_ids as $value){
        print_r($value);
        foreach($value as $val){
            echo $val;
        }
    }
    $dataProvider=new CActiveDataProvider('Lecture', array(
        'criteria'=>array(

            'condition'=>'subject_id='+$val,
        )
    ));

    return $dataProvider;

}

我应该如何使用数组有多行

1 个答案:

答案 0 :(得分:1)

你的功能应该是

public function myDataProvider($subject_ids)
{
    $criteria = new CDbCriteria;
    $criteria->compare('subject_id=', $subject_ids);
    $dataProvider=new CActiveDataProvider('Lecture', array(
        'criteria'=>$criteria
    ));

    return $dataProvider;
}

但是$ subject_ids在你的例子中不是int数组,所以你可以这样做:

$ids = CHtml::listData(subject::model()->findAll($criteria), 'id', 'id');

你会得到ids。