1

我在使用 VichUploaderBundle 时遇到问题。正确上传文件,但是当我写

<td><img src="<img src="{{ vich_uploader_asset(entity, 'image') }}" alt="{{ entity.nombre }}" />"</td>

显示上传的图片,我有这个错误:

An exception has been thrown during the rendering of a template ("Unable to get filename property value: "image"") in SuperlineaBundle:Instruccion:index.html.twig at line 21.

我试图在控制器上获得帮助,它可以工作:

$helper = $this->container->get('vich_uploader.templating.helper.uploader_helper');
$path = $helper->asset($entities[0], 'image');
ladybug_dump( $path );

显示:字符串(25)“/images/uploads/video.png”

任何帮助或线索?

这是我的实体: http: //pastebin.com/d8X72zK4 这是我的配置:

vich_uploader:
    db_driver: orm
    twig: true
    gaufrette: false # set to true to enable gaufrette support
    storage: vich_uploader.storage.file_system
    mappings:
        uploads:
            uri_prefix: /images/uploads
            upload_destination: %kernel.root_dir%/../web/images/uploads
            namer: ~ # specify a file namer service id for this entity, null default
            directory_namer: ~ # specify a directory namer service id for this entity, null default
            delete_on_remove: true # determines whether to delete file upon removal of entity
            inject_on_load: true # determines whether to inject a File instance upon load
        pdfs:
            uri_prefix: /images/pdf
            upload_destination: %kernel.root_dir%/../web/images/pdf
            namer: ~ # specify a file namer service id for this entity, null default
            directory_namer: ~ # specify a directory namer service id for this entity, null default
            delete_on_remove: true # determines whether to delete file upon removal of entity
            inject_on_load: true # determines whether to inject a File instance upon load

这是我的树枝模板:...

{% for entity in entities %}
        <tr>
            <td><a href="{{ path('instruccion_show', { 'id': entity.id }) }}">{{ entity.id }}</a></td>
            <td>{{ entity.nombre }}</td>
            <td>{{ entity.foto }}<img src="<img src="{{ vich_uploader_asset(entity, 'image') } }" alt="{{ entity.nombre }}" />"</td>
            <td>{{ entity.video }}</td>
            <td>
                <ul>
                    <li>
                        <a href="{{ path('instruccion_show', { 'id': entity.id }) }}">show</a>
                    </li>
                    <li>
                        <a href="{{ path('instruccion_edit', { 'id': entity.id }) }}">edit</a>
                    </li>
                </ul>
            </td>
        </tr>
    {% endfor %}
4

3 回答 3

6

我也有这个问题。我是由我的实体加载方式引起的。我显示的实体是另一个实体的属性。

细节:

https://github.com/dustin10/VichUploaderBundle/issues/109

https://github.com/dustin10/VichUploaderBundle/issues/28

我希望这可以帮助别人!

谢谢,加夫

于 2013-01-24T14:52:54.253 回答
1

如果目标字段具有空值,则会发生这种情况,您需要在调用 vich_uploader_asset 之前对其进行测试。尝试这个:

<td>
{# foto is the uploader target field in your entity #}
{% if entity.foto %}
<img src="{{ vich_uploader_asset(entity, 'image') }}" alt="{{ entity.nombre }}" />
{% else %}
{# display nothing, or use a generic image #}
<img src='no-img.png' alt='{{ entity.nombre }}' />
{% endif %}
</td>
于 2013-08-07T18:29:52.860 回答
1

更正这条线

<td>{{ entity.foto }}<img src="<img src="{{ vich_uploader_asset(entity, 'image') } }" alt="{{ entity.nombre }}" />"</td>

你有双 img 标签

于 2012-10-10T18:35:55.077 回答