Closed djfly closed 10 years ago
What's the problem exactly?
selected does not depend on model, we can manually set
In my case, $ model-> parent has a value, but I do not want it to display this value, I need to set another value
this is my proposal
<?= $form->field($model, 'parent')->dropDownList($items, ['value' => $parent->id]) ?>
does Category
model has a parent_id
and is parent
the relation?
not relation ,just set a selected value for select
<select id="category-parent" class="form-control" name="Category[parent]">
<option value="34">one</option>
<option value="35">two</option>
<option value="35" selected="">three</option>
</select>
I mean, this function should be added a argument for set selected value https://github.com/yiisoft/yii2/blob/master/framework/widgets/ActiveField.php line 517
public function dropDownList($items, $options = [])
{
...
one solution is
public function dropDownList($items,$selection)
Another solution is
public function dropDownList($items, ['options' => ['value => xxx]]) ?>
you can do it like this, there is no need for this option:
<?php
$model->parent = $parent->id;
echo $form->field($model, 'parent')->dropDownList($items);
?>
general:
Practical work:
I think this should be better
Some people experience the same confusion it?