代码之家  ›  专栏  ›  技术社区  ›  Kennethvr

如何在Symfony表单选择框中设置所选选项

  •  4
  • Kennethvr  · 技术社区  · 17 年前

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

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

    或者,这必须在创建此表单的类中完成吗? 字段的创建已完成:

    public function configure() {
        $this->widgetSchema['field'] = new sfWidgetFormSelect(
          array("choices" => 
              array('1' => 'test1','2' => 'test2')
          )
        );
      }
    
    1 回复  |  直到 15 年前
        1
  •  2
  •   Andrei Dziahel vjache    17 年前

    是的,您确实应该通过以下方式设置相应的表单值 bind() default

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

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

    推荐文章