The desired list with multiple selections - in yii

I need a multiple choice list in yii, I have a code for the form region but its saving in the database as the word "Array" in the field, How to handle this problem?

how to return to view, update and grid also

<?php echo $form->dropDownList($model,'clients', 
  CHtml::listData(client::model()->findAll(array('order'=>'id')), 'id', 'name'),
     array('empty'=>'','multiple'=>'multiple','style'=>'width:400px;','size'=>'10'));
?>

Thank.

+3
source share
5 answers

For me this works:

'multiple'=>true

Your code should be something like this:

<?php echo $form->dropDownList($model,'clients', 
  CHtml::listData(client::model()->findAll(array('order'=>'id')), 'id', 'name'),
     array('empty'=>'','multiple'=>true ,'style'=>'width:400px;','size'=>'10'));
?>
+3
source

If this is an attitude, you can use this: http://yiiext.github.com/activerecord-relation-behavior/ , which takes care of preserving the array in many ways ..

, , , , , , , .

0

$arr = implode(",",$model->attributes['hobbies']);

$model->hobbies=$arr;

, if

0
$htmlOptions = array('size' => '5', 'multiple' => 'true','style'=>'width: 333px');

$model->field_id    =   array_of_data_to_be_selected

$form->listBox($model,'field_id',$listData, $htmlOptions);

0

CHtml:: listBox()

if(!empty($htmlOptions['multiple']))
{
    if(substr($name,-2)!=='[]')
        $name.='[]';
}

So you can try this

<?php echo $form->dropDownList($model,'clients', 
    CHtml::listData(client::model()->findAll(array('order'=>'id')), 'id', 'name'),
    array(
>>>     'name'=>CHtml::resolveName($model, 'clients').'[]',
        'empty'=>'',
        'multiple'=>'multiple',
        'style'=>'width:400px;',
        'size'=>'10',
    )
);?>

But it is better to use CHtml :: listBox ()

0
source

All Articles