donglvlao8367 2011-06-21 14:20
浏览 26
已采纳

Symfony嵌入式表单 - 可能不显示嵌入式表单的“父”标签?

When you embed a form in Symfony, a label for the embedded form is injected into the parent form. For example: If I have a PersonForm and add this code $this->embedForm('Address', $addressForm), my PersonForm will now have an 'Address' label within it, in addition to the labels for the fields that make up the AddressForm. I'd like to keep the labels for the individual fields, but get rid of the 'Address' label, thereby making it appear that the two forms are really one.

It's possible to override the form template and manually iterate over the form elements and echo them one by one, but I run into this situation frequently and I'd prefer to have Symfony handle this automatically.

  • 写回答

3条回答 默认 最新

  • douju1365 2011-06-22 13:54
    关注

    Here is a simple way of disabling all labels. Add this method to BaseForm if you do it frequently.

    public function disableLabels()
    {
      $fields = $this->getWidgetSchema()->getFields();
      $this->getWidgetSchema()->setLabels(array_combine(array_keys($fields), array_fill(0, count($fields), false)));
    }
    

    If you only want to disable labels in the embedded form, disable them before embedding:

    $form = new FormToEmbed();
    $form->disableLabels();
    $parent->embedForm('child', $form);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序