PHP Yii - ActiveDropDownList () option selected

I have the following active dropdown

<?php 
echo CHtml::activeDropDownList($project, 'city', CHtml::listData(City::model()->findAll(), 'id', 'name'), array('class'=>'st-form', 'onchange' => 'getLocationByCity(this)')); 
?>

I want to add the selected option to the 10th value in the drop-down list when creating a list of how to do this.

Thank.

+5
source share
1 answer

The drop-down list automatically selects the parameter corresponding to the value of the specified attribute of the specified model. In this case, an option is selected with a value equal to $project->city.

So, if you want to control which option, just do

$project->city = $valueOfThatOption;

before calling activeDropDownList.

It doesn’t matter (and should not) if this parameter is 1, 10 or something else.

+5
source

All Articles