vich上传器和简易管理图像未显示

时间:2018-11-14 21:00:15

标签: symfony image-uploading vichuploaderbundle symfony2-easyadmin

我遇到了问题,如果有人知道发生了什么,请提供帮助, 我正在按照(https://symfony.com/doc/master/bundles/EasyAdminBundle/integration/vichuploaderbundle.html

中的教程进行操作

我能够上传图片,但是它没有出现在easy-admim的列表视图中

它是这样的:

#easy_admin.yaml
easy_admin:
  entities:
    Manchete:
      class:  App\Entity\Manchete
      form:
        fields:
          - titulo
          - descricao
          - link
          - {  property: 'arquivoDaImagem', type: 'vich_image', base_path: '%app.path.manchete_images%',
               help: 'selecione uma imagem para a manchete',
                , label: 'Imagem da manchete', template: 'vich_uploader_image.html.twig' }



      # ...
      list:
        fields:
        - titulo
        - descricao
        - link
        - {  property: 'imagem', template: 'vich_uploader_image.html.twig' }
      # ...
      show:
        fields:
        - titulo
        - descricao
        - link
        - {  property: 'imagem', template: 'vich_uploader_image.html.twig' }

bellow是上传文件的路径->

#vich_uploader.yalm
vich_uploader:
    db_driver: orm

    mappings:
        manchete_images:
            uri_prefix: '%app.path.manchete_images%' 
            upload_destination: '%kernel.project_dir%/%app.path.manchete_images%'

#services.yaml
parameters:
    locale: 'en'
    app.path.manchete_images: /uploads/images/manchetes

  

文件和图像正在上传到文件夹:

enter image description here


  

但是没有显示在简单的管理员视图中

enter image description here

所以这是我第一次使用symfony所有这些相关技术,所以我在这里有点迷路了...

在此先感谢您的回复...

2 个答案:

答案 0 :(得分:3)

您应将图像放在 public 文件夹下,尝试以下映射配置:

   manchete_images:
            uri_prefix:         '%app.path.manchete_images%'
            upload_destination: '%kernel.project_dir%/public/%app.path.manchete_images%'

答案 1 :(得分:0)

是的,感谢@Ahmed的建议,它现在正在显示... 认为uri_prefix应该包含单引号,否则会发生异常...

像这样:

manchete_images:
            uri_prefix:  '%app.path.manchete_images%'   
            upload_destination:  '%kernel.project_dir%/public/%app.path.manchete_images%'

enter image description here

再次感谢...