gpt4 book ai didi

php - 如何在嵌套管理中执行内联编辑?

转载 作者:IT王子 更新时间:2023-10-29 01:10:48 27 4
gpt4 key购买 nike

我的问题如下。我正在将 Sonata Admin 与 Symfony 一起使用。在 Admin 部分,当我尝试创建实体时,单击添加按钮(拼写为“Ajouter”)时没有显示任何内容:

enter image description here

我收到以下错误:在 chrome 控制台中调用非对象上的成员函数 getName()

这是我的实体层次结构,我有三个对象以下列方式链接在一起:

Video ---OneToOne--> String ---OneToMany--> LocalizedString

简单地说,我有一个视频,它会有一个标题,并且这个标题会被翻译。这是我的实体:

本地化字符串

OSC\UtilsBundle\Entity\LocalizedString:
type: entity
table: null
repositoryClass: OSC\UtilsBundle\Entity\LocalizedStringRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
locale:
type: string
length: '20'
content:
type: string
length: 255

manyToOne:
parent:
targetEntity: String
mappedBy: localizedObjects


lifecycleCallbacks: { }

字符串

OSC\UtilsBundle\Entity\String:
type: entity
table: null
repositoryClass: OSC\UtilsBundle\Entity\StringRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO

oneToMany:
localizedObjects:
targetEntity: LocalizedString
mappedBy: parent
cascade: ["persist", "remove"]

lifecycleCallbacks: { }

视频

OSC\MySportBundle\Entity\Video:
type: entity
table: null
repositoryClass: OSC\MySportBundle\Entity\VideoRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO

oneToOne:
title:
targetEntity: OSC\UtilsBundle\Entity\String
cascade: ["persist", "remove"]

lifecycleCallbacks: { }

所以,我这样做是为了方便在 SonataAdmin 中进行编辑。如果通过管理仪表板,我想编辑一个字符串,我可以轻松地编辑一个字符串并将其翻译成多种语言(这已经有效)。

但是,当我尝试在视频管理中执行此操作时,我似乎无法对字符串对象进行内联编辑(单击添加按钮不起作用)。

这是视频管理类中的相关代码:

$formMapper
->add('title', 'sonata_type_admin', array('delete' => false, 'btn_add' =>false), array(
'edit' => 'inline',
'inline' => 'table',
));

根据我的发现,看起来不可能有两种叠瓦形式?有没有办法绕过这个限制?或者可能是我的设计不太好?

Edit1: github 上好像有一个补丁:https://github.com/sonata-project/SonataAdminBundle/pull/1971#issuecomment-58023124

如果有人知道我如何使用它,我将不胜感激。

最佳答案

在您的代码中,您使用的 delete 不是有效选项。也许你可以试试 'btn_delete' => false查看所有有效选项的文档 here .

如果这不起作用,也许 sonata_type_collection 是解决您问题的方法。确保根据您的关系以正确的方式使用 by_reference 选项。

关于php - 如何在嵌套管理中执行内联编辑?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26206971/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com