我在使用 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 %}