2015-05-20 171 views
1

我在TWIG的下一個對象:TWIG無法訪問對象屬性

{{dump(profile.profileTagOne)}} 

Tag {#2306 ▼ 
    +__isInitialized__: true 
    #id: 1 
    #name: "This is my name" 
    #slug: "this-is-my-name" 
    #native: true 
    #perfil: PersistentCollection {#2307 ▶} 
    …4 
} 

如果我告訴了var profile.profileTagOne我的名字,但如果我嘗試訪問的id我得到的錯誤:不可能通過profile.profileTagOne.id

任何想法來訪問一個NULL變量(「」)的屬性(「ID」)在...,我想訪問?

+1

你確定沒有一些'{%for%}'看看周圍,你想要訪問一些其他的對象嗎? –

回答

3

根據VarDumper component的文檔,以#爲前綴的屬性爲protected,這意味着您無法直接訪問它們。

您可能需要更改Tag::$id的可見性或編寫一個公開可見性吸氣劑。 Tag是否有getId()方法?