0

大家好,由于某种原因,当我指定自己的标签时,表单生成器为我制作了两个标签。

这是 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

这是构建表单:

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
        ))

我在上面有第二个标签...

在此处输入图像描述

我看过上传器模板,没有标签:

{% 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'

有什么可能做到这一点?

4

4 回答 4

1

我遇到了同样的问题,显然没有解释。反复阅读文档时,我意识到我忘记了下面的配置。它解决了我的问题:

# app/config/config.yml
twig:
    form_themes:
        # other form themes
        - 'VichUploaderBundle:Form:fields.html.twig'
于 2016-01-12T18:23:47.257 回答
1

在上传器模板中执行此操作

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

或其他人说在树枝中您可以将标签设置为 false'label'=>false

于 2016-03-10T17:01:19.877 回答
1

这是一个老问题,但尚未得到正确回答,因此,以供将来参考:

在 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)

于 2017-04-02T23:35:48.420 回答
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
))
于 2016-07-10T17:49:46.933 回答