list options for dropDownList

Hi,

in a normal HTML page when you create a select list where the value attribute is not defined of option tags then the text is served as values. see example below…




<select>

[indent]<option>value 1</option>[/indent]

[indent]<option>value 2</option>[/indent]

[indent]<option>value 3</option>[/indent]

</select>



I want to achieve same thing in


CHtml::dropDownList()

method. I am providing this array


array('1 week', '2 weeks', '1 month', '3 months', '6 months', '1 year')

in the data parameter of the method. The resulting HTML is this


<select name="recent" id="recent">

<option value="">-select-</option>

<option value="0">1 week</option>

<option value="1">2 weeks</option>


<option value="2">1 month</option>

<option value="3">3 months</option>

<option value="4">6 months</option>

<option value="5">1 year</option>

</select>

How to avoid array keys to appear in the values. I know we can specify the keys explicitly same as the text but then the array grows with redundant text. Thats how it looks to me.

Any suggestions?

Thank you.

I wouldn’t care much about redundancy here. Specifying values is the safer way to go. What e.g. if you later want to use different languages for your application? Option values then would also change. Usually that’s not a desired behavior.

For now you could easiliy prepare your options like this:


$values = array('1 week',...);

$opts=array_combine($values,$values)

WOW!!! you rock! :)

i was doing the same stuff in a much more complicated way… thanks a lot!