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 member.id is as well in session.data (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,
),
));
Regards,
ycast