What is the difference between these two drop down lists?
If I want to use the same drop down list on two different pages, which one is best suited for this?
What is the difference between these two drop down lists?
If I want to use the same drop down list on two different pages, which one is best suited for this?
They are the same, except that the active one gets its current value from a model.
When would you need to do that? The current value can always be got by accessing the element in $_GET or $_POST can’t it?
When rendering a view.
I don’t get it. In my view I just have:
<?php echo CHtml::dropDownList('sort',$_GET['sort'],array(......)); ?>
And that does the job. What benefit does the active method give?
You get the value from the model in the input field, don’t you.
The activeDropDownList will initialise the ‘selected’ value.
Useful mainly for updating an existing record.
For example, if you saved a new record with a country chosen from a list, when editing/updating this record your chosen country would be shown as selected.
I only tend to use the ‘active’ form elements to be honest.
Wow, this is an old post
If I use either, i get exactly the same thing… and BOTH auto select the current value from the DB…
So, to me, it must be a speed thing, becasue cant tell the difference otherwise…
What im stuck with, is that it wont sort the ages… it shows them in the order they were saved in the database (rather than 0-100)… any ideas?
<?php echo $form->dropDownList($model,'client_1_age', CHtml::listData(FormFields::model()->findAll('id_field=2',array('order' => 'value')), 'value', 'value'), array('empty'=>'Select age')) ?>
<?php echo CHtml::activeDropDownList($model, 'client_1_age', CHtml::listData(FormFields::model()->findAll('id_field=2',array('order' => 'value')), 'value', 'value'), array('empty'=>'Select age')) ?>
They’re the same, if you read above the comparison is between CHtml::dropDownList and CHmtl::activeDropDownList. As datashaman pointed out, the active one gets the value from a model, both $form->dropDownList and CHtml::activeDropDownList gets its values from a model.
I know this $form->dropDownList is the new way to do it.