0
我更喜歡在symfony2中使用PHP Template Engine來Twig,因爲它有一定的靈活性,而且我更習慣使用它。例如,當打印出某些東西時,我會喜歡使用'ternary If'之類的東西。Symfony 2 PHP模板引擎渲染對象
我現在的問題是,我的數據在模板上呈現爲對象。使用(數組)似乎沒有幫助,因爲我最終得到了像這樣的東西;
array (size=4)
'�news\newsBundle\Entity\News�id' => int 1
'�news\newsBundle\Entity\News�title' => string 'News title 1' (length=12)
'�news\newsBundle\Entity\News�body' => string 'Some body text' (length=14)
'�news\newsBundle\Entity\News�createdDate' =>
object(DateTime)[306]
public 'date' => string '2014-11-05 19:41:48.000000' (length=26)
public 'timezone_type' => int 3
public 'timezone' => string 'Europe/London' (length=13)
如何獲得像普通數組例如array('id'=> int 1)的結果,而沒有命名空間的東西。
在此先感謝
'twig'還支持'三元if' - http://twig.sensiolabs.org/doc/templates.html#other-operators – Cheery 2014-11-06 00:10:59