Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

CActiveForm->dropDownList selected="selected"

$
0
0
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:
$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 :)

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>