4

我有一个用 Symfony 表单创建的表单。

在模板中我有这个选择框,用渲染方法显示在页面上。

<?php echo $form['field']->render() ?>

是否可以设置此选择框的选定选项?

还是必须在创建此表单的类中完成?完成了字段的创建:

public function configure() {
    $this->widgetSchema['field'] = new sfWidgetFormSelect(
      array("choices" => 
          array('1' => 'test1','2' => 'test2')
      )
    );
  }
4

1 回答 1

2

是的,当然——你应该设置相应的表单值——或者通过bind(),或者通过小部件的default选项。

例如,

public function configure() 
{
    $this->widgetSchema['field'] = new sfWidgetFormSelect(array(
        "choices" => array('1' => 'test1','2' => 'test2'), 
        'default' => 2));
}

希望我已经回答了你的问题。

于 2009-06-18T11:57:33.200 回答