【问题标题】:Easyadmin bundle + sf 4 : can't display a field in formEasyadmin bundle + sf 4:无法在表单中显示字段
【发布时间】:2020-01-14 14:46:55
【问题描述】:

我正在尝试设置我的产品创建页面并配置表单。 我有 2 个实体:Product 和 ProductTranslates

数据库

产品

product_translate

product_id_id 上有一个外键(不知道为什么我有两个“id”...)

我想在我的 product.yaml 中使用一些 product_translates 字段(见下文)

例如,我想在我的表单中添加“描述”。 你知道我该怎么做吗?我可以轻松地使用“产品”属性,但不知道如何处理 yaml 文件中的 product_translate。

非常感谢!!!

easy_admin:
  entities:
    # the configuration of this entity is very verbose because it's used as
    # an example to show all the configuration options available for entities
    # check out the configuration of the other entities to see how concise
    # can be the configuration of your backend
    Product:
      class: App\Entity\Product
      label: 'Produits'
      list:
        ...
      form:
        title: 'Créer un produit'
        fields:
          - { property: 'univers', label: 'univers' }
          - { property: 'product_code', label: 'Référence', type: 'number' }
          - { property: 'category_id', label: 'Catégorie', type: 'easyadmin_autocomplete', type_options: { class: 'App\Entity\Product' } }
          - { property: 'is_cocktail', label: 'Est-ce un cocktail ?', type: 'checkbox' }
          - { property: 'is_active', label: 'Voulez vous le publier ?', type: 'checkbox' }
          - { property: 'alcohol_volume', label: 'Degré d''alcool', type: 'number' }
          - { property: 'created_at', label: 'Date de création', type: 'datetime' }
          - { property: 'photo', type: 'file', label: 'Uploader une photo', help: 'Sélectionner le fichier' }
      edit:
        ...

最终结果:

【问题讨论】:

    标签: symfony bundle symfony4 sf easyadmin


    【解决方案1】:

    您可以在easy admin中嵌套另一种表单类型(如果关系是@OneToOne),或者添加ProductTranslate的集合(如果关系是@ManyToOne),
    第一个变体:

    fields:
              - { property: 'univers', label: 'univers' }
              - { property: 'product_code', label: 'Référence', type: 'number' }
              - { property: 'category_id', label: 'Catégorie', type: 'easyadmin_autocomplete', type_options: { class: 'App\Entity\Product' } }
              - { property: 'is_cocktail', label: 'Est-ce un cocktail ?', type: 'checkbox' }
              - { property: 'is_active', label: 'Voulez vous le publier ?', type: 'checkbox' }
              - { property: 'alcohol_volume', label: 'Degré d''alcool', type: 'number' }
              - { property: 'created_at', label: 'Date de création', type: 'datetime' }
              - { property: 'photo', type: 'file', label: 'Uploader une photo', help: 'Sélectionner le fichier' }
              - { property: 'productTranslate', label: 'Description', type: ProductTranslateType }
    

    第二个变种

    fields:
              - { property: 'univers', label: 'univers' }
              - { property: 'product_code', label: 'Référence', type: 'number' }
              - { property: 'category_id', label: 'Catégorie', type: 'easyadmin_autocomplete', type_options: { class: 'App\Entity\Product' } }
              - { property: 'is_cocktail', label: 'Est-ce un cocktail ?', type: 'checkbox' }
              - { property: 'is_active', label: 'Voulez vous le publier ?', type: 'checkbox' }
              - { property: 'alcohol_volume', label: 'Degré d''alcool', type: 'number' }
              - { property: 'created_at', label: 'Date de création', type: 'datetime' }
              - { property: 'photo', type: 'file', label: 'Uploader une photo', help: 'Sélectionner le fichier' }
              - { property: 'productTranslates', label: 'Product translates', type: collection, type_options: { entry_type: ProductTranslateType }
    

    当然你需要提供自定义表单类型的完整路径(命名空间+类)

    【讨论】:

    • 感谢您的帮助,我将探索该解决方案!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-18
    • 2021-09-29
    • 2011-11-09
    相关资源
    最近更新 更多