CActiveDataProvider criteria from other table

Hi all,

It seems I am beyond my capabilities with a elegant solution to the following requirement:

I would like to retrieve items from my table ‘member’ with CActiveDataProvider. But only those items, where the is as well in (as a serialized array from CDbHttpSession).

The following code does work, but it seems pretty crappy.

Maybe one of you knows a way with a Yii built-in feature (such as AR relation,…)?

// Create criteria for WHERE clause

// Create string from array (e.g. 1, 2, 3, 4, 5, 6)

if (!empty(Yii::app()->session['selection'])) {

    $criteria = implode(', ', Yii::app()->session['selection']);

} else {

    $criteria = '0';


// Retrieve data based on criteria

$dataProvider = new CActiveDataProvider('Member', array(

    'criteria' => array(

        // e.g. 'id IN (1, 2, 3, 4, 5, 6)'

        'condition' => 'id IN ('.$criteria.')',


    'pagination' => array(

        'pageSize' => 12,






I’d like to thank for this post, as I was given the idea how to filter the $dataProvider in the controller by passing additional parameters upon instantiating CActiveDataProvider class. I love Yii!

Following is my snippet:

                    $dataProvider=new CActiveDataProvider('User', array(

                        'criteria' => array(

                            'condition' => 'email IS NOT NULL',