symfony对象图像多对多

symfony对象图像多对多,symfony,Symfony,我有一个数据库,需要有一个对象的多个图像。 在列表视图中,我看到了多个图像,但它出现在文本中,我需要有图像 这是我的产品实体的列表映射器(一个产品具有多个图像) } 这是我“形象”的小枝 {% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %} {% block field %} <a href="{{ asset('uploads/documents/') }}{{ value|nl2br }}">&

我有一个数据库,需要有一个对象的多个图像。 在列表视图中,我看到了多个图像,但它出现在文本中,我需要有图像

这是我的产品实体的列表映射器(一个产品具有多个图像)

}

这是我“形象”的小枝

{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}

{% block field %}
    <a href="{{ asset('uploads/documents/') }}{{ value|nl2br }}"><img class="admin-list-preview" src="{{ asset('uploads/documents/') }}{{ value|nl2br }}"/></a>
{% endblock %}
转储值


如果你看不到自己的图像,请使用以下结构:

{{ asset('uploads/documents/' ~ object.image ) }}
uploads/documents/ - folder to you directory with images.
object.image - image name (twig variable)
SonataAdminBundle示例

{% for image in object.image %} 
     <img class="admin-list-preview" src="{{ asset('uploads/documents/' ~ image) }}"/> 
{% end for %}
{%for object.image%}
{%end for%}

谢谢,我尝试了此操作,但它给了我以下消息错误:在呈现模板期间引发了异常(“可捕获的致命错误:类的对象条令\ORM\PersistentCollection无法转换为字符串”)在第3行的AdminBundle::Admin/list\u types/image.html.twig.template AdminBundle::Admin/list\u types/image.html.twig{%extends'SonataAdminBundle:CRUD:base\u list\u field.html.twig%}{%block field%}{%endblock%}中,您试图显示的对象是一个集合,因此必须循环以包含其中的所有元素。你能把它扔了吗?好的,那么首先:你现在有什么?你想要什么第二:你真的有文件上传到你的服务器上吗可以使用dump()在视图中转储图像对象
AdminBundle\Entity\Products:
    type: entity
    table: null
    sortable: true
    repositoryClass: AdminBundle\Repository\ProductsRepository
    id:
        id:
            type: integer
            id: true
            generator:
                strategy: AUTO
    fields:
        name:
            type: string
            length: 255
        descriptionshortnat:
            type: text
            length: 500
            nullable: true
        descriptionlongnat:
            type: text
            length: 5000
            nullable: true
        descriptionshorten:
            type: text
            length: 500
            nullable: true
        descriptionlongen:
            type: text
            length: 5000
            nullable: true
        created:
            type: datetime
            nullable: true
            gedmo:
              timestampable:
                on: create
        updated:
            type: datetime
            nullable: true
            gedmo:
              timestampable:
                on: update
    lifecycleCallbacks:
      prePersist: [ setCreatedAtValue,setUpdatedAtValue ]
      preUpdate: [ setUpdatedAtValue ]
    manyToOne:
        country:
            targetEntity: AdminBundle\Entity\Country
            joinColumn:
                name: country
                referencedColumnName: id
            nullable: TRUE
        category:
            targetEntity: AdminBundle\Entity\Category
            joinColumn:
                name: category
                referencedColumnName: id
            nullable: TRUE
        preservation:
            targetEntity: AdminBundle\Entity\Preservation
            joinColumn:
                name: preservation
                referencedColumnName: id
            nullable: TRUE
        population:
            targetEntity: AdminBundle\Entity\Population
            joinColumn:
                name: population
                referencedColumnName: id
            nullable: TRUE
        innovation:
            targetEntity: AdminBundle\Entity\Innovation
            joinColumn:
                name: innovation
                referencedColumnName: id
            nullable: TRUE
        timeframe:
            targetEntity: AdminBundle\Entity\Timeframe
            joinColumn:
                name: timeframe
                referencedColumnName: id
            nullable: TRUE
        component:
            targetEntity: AdminBundle\Entity\Component
            joinColumn:
                name: component
                referencedColumnName: id
            nullable: TRUE
    manyToMany:
        contact:
            targetEntity: AdminBundle\Entity\Contact
            joinTable:
                name: allproducts
                joinColumns:
                    products:
                        referencedColumnName: id
                inverseJoinColumns:
                    contact:
                        referencedColumnName: id
        organisation:
            targetEntity: AdminBundle\Entity\Organisation
            joinTable:
                name: allorganisation
                joinColumns:
                    product:
                        referencedColumnName: id
                inverseJoinColumns:
                    organisation:
                        referencedColumnName: id
        competition:
            targetEntity: AdminBundle\Entity\Competition
            joinTable:
                name: allcompetition
                joinColumns:
                    competition:
                        referencedColumnName: id
                inverseJoinColumns:
                    product:
                        referencedColumnName: id
        image:
            targetEntity: AdminBundle\Entity\Image
            joinTable:
                name: allpictures
                joinColumns:
                    product:
                        referencedColumnName: id
                inverseJoinColumns:
                    image:
                        referencedColumnName: id
{{ asset('uploads/documents/' ~ object.image ) }}
uploads/documents/ - folder to you directory with images.
object.image - image name (twig variable)
{% for image in object.image %} 
     <img class="admin-list-preview" src="{{ asset('uploads/documents/' ~ image) }}"/> 
{% end for %}