我的問題如下。我正在使用Symfony的Sonata Admin。在管理部分,當我試圖創建一個實體,沒事的時候我點擊添加按鈕(拼寫爲「Ajouter」)顯示:如何在嵌套管理器中執行嵌入式編輯?
我收到以下錯誤:Call to a member function getName() on a non-object
在Chrome控制檯
這裏是我的實體層次是怎麼了,我有一個在下面的方式聯繫在一起的三個對象:
Video ---OneToOne--> String ---OneToMany--> LocalizedString
簡單地說,我有一個視頻,將有一個標題和這個稱號將被翻譯。這裏是我的實體:
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中進行編輯。如果通過管理儀表板,我想編輯一個字符串,我可以輕鬆地編輯一個字符串並以多種語言翻譯它(這已經有效)。
但是,當我嘗試在視頻管理中執行此操作時,似乎無法對String對象進行內聯編輯(單擊添加按鈕不起作用)。
下面是視頻管理類的相關代碼:
$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
如果有誰知道我該如何使用它,我將不勝感激。
只需使用'sonata_type_model'並傳遞相關選項以獲得更好的控制 – 2014-12-16 14:47:27
您是否嘗試過使用sonata_type_collection而不是sonata_type_admin與inline =>'table''的'inline'=>'standard''? – 2016-11-25 00:36:42
還有什麼是您的StringAdmin? – 2016-11-25 00:38:51