I am new in yii. I have problem with fetching selected values in dropdown when updating the record.
I have dropdown with multiple selection of user's email.
When adding it is working fine, it allows me to select multiple values and can insert selected value's ids comma separated in database.
But the problem is when i want to update the record it displays only 1 selected record.
Here is my code:
in my View 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 my Controller file:
$model = new User;
$allUsers = $model->getAllUsers();
in my 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?