zoukankan      html  css  js  c++  java
  • symfony CollectionType类型字段子表单字段移除

    工作中我们经常会遇到子表单字段移除工作,哪怎么移除提不想要的子表单字段呢。代码如下

     1     public function buildForm(FormBuilderInterface $builder, array $options)
     2     {
     3         $builder
     4             ->add('stocks', CollectionType::class, [
     5                 'label'         => false,
     6                 'entry_type'    => ProductStockType::class,
     7                 'entry_options' => [
     8                     'label' => false,
     9                 ],
    10                 'allow_delete'  => true,
    11             ])
    12         ;
    13 
    14         $builder->get('stocks')->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $event){
    15             foreach ($event->getForm()->all() as $f)
    16                 $f->remove('status');
    17         });
    18     }
  • 相关阅读:
    zfs
    targetcli
    targetcli
    自动制linux iso包
    yum解决重复包,依赖冲突问题
    lvm相关
    vmware相关
    配置本地yum源
    k8s安装prometheus监控
    流水线基础-Pipeline
  • 原文地址:https://www.cnblogs.com/mickeyooo/p/9417433.html
Copyright © 2011-2022 走看看