How to mark option in dropDownList as selected="selected"?
I have table users witch have filed: location (this field holds id of entry from table: locations)
I'm retrieving data for dropDownList in this way:
This is snippet from my View:
What I have to put in options array in my view so it will work like this pseudocode:
Thanks in advance
I have table users witch have filed: location (this field holds id of entry from table: locations)
I'm retrieving data for dropDownList in this way:
$criteria = new CDbCriteria; $criteria->order = 'name ASC'; $locations = Locations::model()->findAll($criteria); $data['locations'] = CHtml::listData($locations, 'id', 'name');
This is snippet from my View:
<div class="row"> <?php echo $form->labelEx($model,'location'); ?> <?php echo $form->dropDownList($model,'location', $locations, array('prompt'=>'Select location')); ?> <?php echo $form->error($model,'location'); ?> </div>
What I have to put in options array in my view so it will work like this pseudocode:
if ($user->location == $locations->id) { markOption(selected="selected"); }
Thanks in advance
