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

表示:string(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

これが誰かに役立つことを願っています!

ありがとう、Gav

于 2013-01-24T14:52:54.253 に答える
1

この行を修正してください

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

あなたは二重のimgタグを持っています

于 2012-10-10T18:35:55.077 に答える
1

これは、ターゲットフィールドの値がnullの場合に発生します。これは、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 に答える