I am new to yii. I have a problem retrieving selected values from a drop-down list when updating a record.
I have a drop down list with multiple user email choices.
When added, it works fine, it allows me to select multiple values and can insert selected identifier values, separated by commas in the database.
But the problem is that when I want to update a record, it only displays 1 selected record.
Here is my code:
in file :
<div class="controls">
<?php echo $form->dropDownList($model, 'uid', $allUsers, array('class' => 'select2-me input-sel_large', 'multiple' => 'true', 'options' => array('' => array('selected' => true)))); ?>
<?php echo $form->error($model, 'uid') ?>
</div>
in the controller file :
$model = new User;
$allUsers = $model->getAllUsers();
in the Model file :
public function getAllUsers() {
$arr = Yii::app()->db->createCommand()
->select('userEmail,pkUserID')
->from('tbl_user')
->queryAll();
$users = array();
if (is_array($arr)) {
foreach ($arr as $value) {
$users[$value['pkUserID']] = $value['userEmail'];
}
}
return $users;
}
Can anyone help?