How To Get Dropdownlist Option Values Same As The Text In The List

I’m new to Yii framework. I created a dropdownlist using the below code -

echo $form->dropDownList($model, 'min_cost', Yii::app()->params['cost_resales']);

This generated a HTML like -

<select id="SearchForm_min_cost" name="SearchForm[min_cost]" >

<option value="">Min</option>

<option value="0">Min Cost</option>

<option value="1">10 lakhs</option>

<option value="2">20 lakhs</option>

<option value="3">30 lakhs</option>

<option value="4">40 lakhs</option>

<option value="5">50 lakhs</option>


But, I don’t know how to get it like this -

<select id="SearchForm_min_cost" name="SearchForm[min_cost]" >

<option value="">Min</option>

<option value="Min Cost">Min Cost</option>

<option value="10 lakhs">10 lakhs</option>

<option value="20 lakhs">20 lakhs</option>

<option value="30 lakhs">30 lakhs</option>

<option value="40 lakhs">40 lakhs</option>

<option value="50 lakhs">50 lakhs</option>


I want the option values same as that in the text. How can I do this.

1 Like

You have to add the values also in the array key of cost_resales array in your Yii::app()-> params…

like …

array( '' => 'Min Cost',

	'10 lakhs' => '10 lakhs'

	// and so on..

Use array combine with the same array:
echo $form->dropDownList($model, 'min_cost', array_combine(Yii::app()->params['cost_resales'], Yii::app()->params['cost_resales']));

1 Like