2016-01-07 39 views
0

嗨,大家回答某些原因,當我指定自己的標籤時,表單生成器使我有兩個標籤。Symfony vichimage上傳在formbuilder中的兩個標籤

下面是VICH像束的配置:

vich_uploader: 
    db_driver: orm 
    mappings: 
     product_image: 
      uri_prefix:   /images/products 
      upload_destination: %kernel.root_dir%/../web/images/products 
      inject_on_load:  false 
      delete_on_update: true 
      delete_on_remove: true 
     apartment_image: 
      uri_prefix:   /images/apartment 
      upload_destination: %kernel.root_dir%/../web/images/apartment 
      inject_on_load:  false 
      delete_on_update: true 
      delete_on_remove: true 
     slide_image: 
      uri_prefix:   /images/slider 
      upload_destination: %kernel.root_dir%/../web/images/slider 
      inject_on_load:  false 
      delete_on_update: true 
      delete_on_remove: true 
     point_image: 
      uri_prefix:   /images/point 
      upload_destination: %kernel.root_dir%/../web/images/point 
      inject_on_load:  false 
      delete_on_update: true 
      delete_on_remove: true 
     object_image: 
      uri_prefix:   /images/object 
      upload_destination: %kernel.root_dir%/../web/images/object 
      inject_on_load:  false 
      delete_on_update: true 
      delete_on_remove: true 
     gallery_image: 
      uri_prefix:   /images/gallery 
      upload_destination: %kernel.root_dir%/../web/images/gallery 
      inject_on_load:  false 
      delete_on_update: true 
      delete_on_remove: true 

這裏是buildForm:

public function buildForm(FormBuilderInterface $builder, array $options) 
{ 
    $builder 
     ->add('translations', 'a2lix_translations',array(
      'required_locales' => array('bg','en') 
     )) 
     ->add('canvas') 
     ->add('mode','checkbox', array('label'=> 'In sell','required'=>false)) 
     ->add('lat','text',array('label'=>'Latitude')) 
     ->add('longt','text',array('label'=>'Longitude ')) 
     ->add('imageLeadFile', 'vich_image', array(
      'label'=>'Lead image Home Page (720x534)', 
      'required' => false, 
      'allow_delete' => true, // not mandatory, default is true 
      'download_link' => true, // not mandatory, default is true 
     )) 
     ->add('imageLocationFile', 'vich_image', array(
      'required' => false, 
      'allow_delete' => true, // not mandatory, default is true 
      'download_link' => true, // not mandatory, default is true 
     )) 
     ->add('imagePinFile', 'vich_image', array(
      'required' => false, 
      'allow_delete' => true, // not mandatory, default is true 
      'download_link' => true, // not mandatory, default is true 
     )) 
     ->add('imageAligmentFile', 'vich_image', array(
      'required' => false, 
      'allow_delete' => true, // not mandatory, default is true 
      'download_link' => true, // not mandatory, default is true 
     )) 
     ->add('imageAligmentIconFile', 'vich_image', array(
      'required' => false, 
      'allow_delete' => true, // not mandatory, default is true 
      'download_link' => true, // not mandatory, default is true 
     )) 
     ->add('imageArchitectureIconFile', 'vich_image', array(
      'required' => false, 
      'allow_delete' => true, // not mandatory, default is true 
      'download_link' => true, // not mandatory, default is true 
     ))->add('imageStageIconFile', 'vich_image', array(
      'required' => false, 
      'allow_delete' => true, // not mandatory, default is true 
      'download_link' => true, // not mandatory, default is true 
     ))->add('imageLocationIconFile', 'vich_image', array(
      'required' => false, 
      'allow_delete' => true, // not mandatory, default is true 
      'download_link' => true, // not mandatory, default is true 
     ))->add('imageGalleryIconFile', 'vich_image', array(
      'required' => false, 
      'allow_delete' => true, // not mandatory, default is true 
      'download_link' => true, // not mandatory, default is true 
     ))->add('imageColumFirstFile', 'vich_image', array(
     'required' => false, 
     'allow_delete' => true, // not mandatory, default is true 
     'download_link' => true, // not mandatory, default is true 
     ))->add('imageColumSecondFile', 'vich_image', array(
     'required' => false, 
     'allow_delete' => true, // not mandatory, default is true 
     'download_link' => true, // not mandatory, default is true 
    ))->add('imageColumThirdFile', 'vich_image', array(
      'required' => false, 
      'allow_delete' => true, // not mandatory, default is true 
      'download_link' => true, // not mandatory, default is true 
    ))->add('imageColumForthFile', 'vich_image', array(
      'required' => false, 
      'allow_delete' => true, // not mandatory, default is true 
      'download_link' => true, // not mandatory, default is true 
     )) 
    ; 
} 

所以,當我試圖讓不同的標籤是這樣的(我想包括尺寸管理員知道需要提供什麼圖像):

 ->add('imageLeadFile', 'vich_image', array(
      'label'=>'Lead image Home Page (720x534)', 
      'required' => false, 
      'allow_delete' => true, // not mandatory, default is true 
      'download_link' => true, // not mandatory, default is true 
     )) 

我得到第二個l阿貝爾在上面......

enter image description here

我所見過的上傳模板,有沒有標籤:

{% block vich_file_widget %} 
{% spaceless %} 
    <div class="vich-file"> 
     {{ form_row(form.file) }} 
     {% if form.delete is defined %} 
     {{ form_row(form.delete) }} 
     {% endif %} 

     {% if download_uri is defined and download_uri %} 
     <a href="{{ download_uri }}">{{ 'download'|trans({}, 'VichUploaderBundle') }}</a> 
     {% endif %} 
    </div> 
{% endspaceless %} 
{% endblock %} 

{% block vich_image_widget %} 
{% spaceless %} 
    <div class="vich-image"> 
     {{ form_row(form.file) }} 
     {% if form.delete is defined %} 
     {{ form_row(form.delete) }} 
     {% endif %} 

     {% if download_uri is defined and download_uri %} 
     <a href="{{ download_uri }}"><img src="{{ download_uri }}" alt="" /></a> 
     {% endif %} 
     {% if show_download_link and download_uri is defined and download_uri%} 
     <a href="{{ download_uri }}">{{ 'download'|trans({}, 'VichUploaderBundle') }}</a> 
     {% endif %} 
    </div> 
{% endspaceless %} 
{% endblock %} 

使用在CoreBundle外部樹枝文件中的配置:

form_themes: 
    # other form themes 
    - 'CoreBundle:VichForm:fields.html.twig' 

什麼可能做到這一點?

回答

1

這是一個老問題b UT斯達康還沒有被正確地回答,那麼,以供將來參考:

在VichUploaderBundle模板文件「fields.html.twig」,這樣做:

<div class="vich-file"> 
    {{ form_widget(form.file) }} 
    {% if form.delete is defined %} 
    {{ form_row(form.delete, {'label': 'Delete'}) }} 
    {% endif %} 

下同事情的圖像小工具。

<div class="vich-image"> 
    {{ form_widget(form.file) }} 
    {% if form.delete is defined %} 
    {{ form_row(form.delete, {'label': 'Delete'}) }} 
    {% endif %} 

(這只是基本Twig BTW)

1

我與同樣的問題,顯然沒有解釋。當重讀和重讀documentation時,我意識到我忘了下面的這個配置。它解決了我的問題:

# app/config/config.yml 
twig: 
    form_themes: 
     # other form themes 
     - 'VichUploaderBundle:Form:fields.html.twig' 
+0

嗚嗚這不是我所添加的配置爲模板的情況下,它是在CoreBundle。那些樹枝實例{%block vich_file_widget%}和{%block vich_image_widget%}位於CoreBundle中,我可以刪除{{form_row(form.file)}},但我不知道它從哪裏出現...... –

1

在上傳模板做到這一點

{% block vich_file_widget %} 
{% spaceless %} 
    <div class="vich-file"> 
     {{ form_widget(form.file) }} {# here is the change #} 

或其他說,在樹枝,你可以將標籤設置爲假'label'=>false

+0

我嘗試了一切,唯一的解決辦法是去除標籤樹枝元素。 –

0

嘗試改變vich_imagefile,像這個:

->add('imageLeadFile', 'file', array(
    'label'=>'Lead image Home Page (720x534)', 
    'required' => false, 
    'allow_delete' => true, // not mandatory, default is true 
    'download_link' => true, // not mandatory, default is true 
))