枚举选择列表。更改<option>标记值</option>

时间:2011-12-14 16:04:52

标签: forms symfony1 doctrine symfony-1.4

默认情况下,Symfony 1.4会生成MySQL枚举的列表元素,如:

<option value="free">free</option>  
<option value="machine">machine</option>

如何更改选项标记值?,例如:

<option value="free">Different value than free</option>

1 个答案:

答案 0 :(得分:0)

您可以使用以下代码:

$choices = $this->getWidget('mywidget')->getChoices();
// supposing we know what needs to change...
$choices[1] = "new value";
// supposing we don't need other options/attributes
$this->setWidget('mywidget', new sfWidgetFormChoice(array('choices' => $choices)));