2014-10-05 85 views
27

我的問題如下。我正在使用Symfony的Sonata Admin。在管理部分,當我試圖創建一個實體,沒事的時候我點擊添加按鈕(拼寫爲「Ajouter」)顯示:如何在嵌套管理器中執行嵌入式編輯?

enter image description here

我收到以下錯誤: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

如果有誰知道我該如何使用它,我將不勝感激。

+0

只需使用'sonata_type_model'並傳遞相關選項以獲得更好的控制 – 2014-12-16 14:47:27

+0

您是否嘗試過使用sonata_type_collection而不是sonata_type_admin與inline =>'table''的'inline'=>'standard''? – 2016-11-25 00:36:42

+0

還有什麼是您的StringAdmin? – 2016-11-25 00:38:51

回答

-3

你說的鉻控制檯提供了錯誤:

Call to a member function getName() on a non-object 

所以這個錯誤不是從JavaScript?

如果來自PHP的錯誤意味着當您嘗試$ object-> getName()(它必須在OSC \ UtilsBundle \ Controller中使用Ctr + f「getName()」在文件編輯器中找到該行)$ object不是一個對象,可以通過因爲你可能獲得obeject數組而不是單個對象。嘗試添加var_dump($object);,你會看到它是什麼。

0

形式映射器試試這個:

$formMapper 
     ->add('title', 'sonata_type_model_list', array(
        'class' => 'YourBundle:String', 
        'required' => false, 
        'delete' => false, 
        'btn_add' =>true, 
       ), array(
        'edit' => 'inline', 
        'inline' => 'table', 
       )) 
      ; 

如果錯誤一直存在試圖獲得看看Doctrine2文檔: Doctrine2 One to One association mapping,然後生成你的實體

0

在你的代碼使用delete這不是一個有效的選項。也許你可以試試'btn_delete' => false 檢查所有有效選項here的文檔。

如果這不起作用,也許sonata_type_collection是解決您的問題。根據你的關係,確保你正在使用by_reference選項。