Symfony3访问twig中entityType的实体名称

时间:2017-10-11 11:53:22

标签: forms symfony

对于某些ajax目的,我需要访问 in twig 到entityType表单字段的实体名称

在我的表单构建器中,我有entityType

->add('categories', EntityType::class, array(
            'label'=>'lilworks.storebundle.categories',
            'class'    => 'LilWorksStoreBundle:Category' ,
            'choice_label' => function ($obj) { return   $obj->getName() ; },
            'query_builder' => function (EntityRepository $er)  {
                return $er->createQueryBuilder('c')
                    ->orderBy('c.name','asc')
                    ->setMaxResults(1)
                    ;
            },
            'required' => true ,
            'mapped'=> true,
            'expanded' => true ,
            'multiple' => true,
            'attr'=> ['class'=>'hidden-row']
        ))

在我的twig视图中,我可以访问我的form.categories.vars,但我找不到entityName“LilWorksStoreBundle:Category”

  "value" => []
  "attr" => array:1 [▶]
  "form" => FormView {#7602 ▶}
  "id" => "lilworks_storebundle_product_categories"
  "name" => "categories"
  "full_name" => "lilworks_storebundle_product[categories]"
  "disabled" => false
  "label" => "lilworks.storebundle.categories"
  "label_format" => null
  "multipart" => false
  "block_prefixes" => array:4 [▶]
  "unique_block_prefix" => "_lilworks_storebundle_product_categories"
  "translation_domain" => null
  "cache_key" => "_lilworks_storebundle_product_categories_entity"
  "errors" => FormErrorIterator {#7601 ▶}
  "valid" => true
  "data" => ArrayCollection {#4197 ▶}
  "required" => true
  "size" => null
  "label_attr" => []
  "compound" => true
  "method" => "POST"
  "action" => ""
  "submitted" => false
  "multiple" => true
  "expanded" => true
  "preferred_choices" => []
  "choices" => array:1 [▶]
  "separator" => "-------------------"
  "placeholder" => null
  "choice_translation_domain" => false
  "is_selected" => Closure {#7603 ▶}
  "placeholder_in_choices" => false

0 个答案:

没有答案