Yes, that work. But my problem is the selected areas. I have a default array (beer, wine, water) and selected products in a model (like beer and water). This would be visible as selected in a listBox of a form.
// $model is a model for customer and bougth products
// $pmodel is a model for products for sale
echo $form->listBox($model,'products',CHtml::listData($pmodel,'product','description'),array('multiple'=>'multiple','size'=>'10','options'=>array( 'Beer'=>array('selected'=>'selected'), 'Wine'=>array('selected'=>'selected') )));
How can I select bought products from $model->products display in options?
// $model is a model for customer and bougth products
// product value in database is comma separeted (Beer,Wine,Water)
// $pmodel is a model for products for sale
<?php echo $form->labelEx($model,'products'); ?>
<?php
if(isset($model->products))
{
// snipe product list and build the option array
$m = explode(",", $model->products);
$x = 0;
foreach ($m as $p)
{
$pp[$p] = array('selected'=>'selected');
$x++;
}
}
echo $form->listBox($model,'products',CHtml::listData($pmodel,'product','description'),array('multiple'=>'multiple','size'=>count($pmodel),'options'=>$pp ));
?>
<?php echo $form->error($model,'products'); ?>