【问题标题】:Symfony 1.4: Print out individual checkboxesSymfony 1.4:打印出单个复选框
【发布时间】:2014-06-01 19:13:25
【问题描述】:

我有以下表单元素,它会生成一个复选框:

 $deliveryLocationChoices    = array( '0' => 'Select if Applicable',
                                       'front'    => 'Front',
                                       'rear'     => 'Rear',
                                       'left'     => 'Left Side',
                                       'right'    => 'Right Side');

 $this->setWidgets(array(
      'delivery_location'   => new sfWidgetFormChoice(array('choices' => $deliveryLocationChoices  )),
 ));

它很好用,但我想打印每个单独的复选框项目。原因是我需要自定义每个框的位置。

谢谢

【问题讨论】:

    标签: symfony-1.4 symfony-forms


    【解决方案1】:

    您可以通过将 renderer_options 参数传递给新的 sfWidgetFormChoice 来覆盖复选框的显示方式。

    看起来像这样

    $this->setWidgets(array(
      'delivery_location'   => new sfWidgetFormChoice(array('choices' => $deliveryLocationChoices, 'renderer_options' => array('formatter' => array($this, 'checkboxFormatter')))),
    ));
    

    然后,在您的表单类中,像这样定义函数“checkboxFormatter”

    public static function checkboxFormatter($widget, $inputs) {}
    

    这样您就可以通过 $inputs 变量访问您的复选框。必须在 checkboxFormatter 函数的最后返回显示结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-05
      • 2011-09-08
      • 2015-02-20
      • 1970-01-01
      相关资源
      最近更新 更多