2014-11-05 88 views
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)的结果,而没有命名空间的东西。

在此先感谢

+0

'twig'还支持'三元if' - http://twig.sensiolabs.org/doc/templates.html#other-operators – Cheery 2014-11-06 00:10:59

回答