Php Can';t在twig模板中呈现一些变量

Php Can';t在twig模板中呈现一些变量,php,zend-framework2,twig,Php,Zend Framework2,Twig,我已经使用ZF2编写了我的应用程序。 我有两个模块:邮件和文件。 将呈现邮件模块中的所有变量。无法渲染对象文件。 当我执行{{dump(mail.file)}}时,它返回NULL。但是如果我执行{{dump()}操作,文件对象确实存在: array (size=2) 'mail' => object(Mail\Entity\Incoming)[453] protected 'id' => int 8 protected 'inNumber' =&

我已经使用ZF2编写了我的应用程序。 我有两个模块:邮件和文件。 将呈现邮件模块中的所有变量。无法渲染对象文件。 当我执行
{{dump(mail.file)}}
时,它返回
NULL
。但是如果我执行
{{dump()}
操作,文件对象确实存在:

array (size=2)
  'mail' => 
    object(Mail\Entity\Incoming)[453]
      protected 'id' => int 8
      protected 'inNumber' => int 1
      protected 'inDate' => int 1320948000
      protected 'outNumber' => string '1' (length=1)
      protected 'outDate' => int 1320948000
      protected 'sheetsNumber' => int 1
      protected 'teaser' => string '' (length=0)
      protected 'file' => 
        object(File\Entity\File)[455]
          protected 'id' => int 5
          protected 'origName' => string 'eRa33cHgofw.jpg' (length=15)
          protected 'curName' => string 'eRa33cHgofw.jpg' (length=15)
          protected 'size' => int 284192
          protected 'type' => string 'image/jpeg' (length=10)
          protected 'uploaded' => int 1385736080
      protected 'sender' => 
        object(Mail\Entity\Sender)[457]
          protected 'id' => int 1
          protected 'name' => string 'ООО Ромашка' (length=21)
      protected 'type' => 
        object(Mail\Entity\Type)[459]
          protected 'id' => int 1
          protected 'name' => string 'Информация' (length=20)
      protected 'created' => int 1385736080
  'namespace' => string 'FileEntityFile' (length=14)

有人帮我吗?

邮件\Entity\Incoming
中的
文件
属性受
保护
,因此它只能从类本身或
邮件\Entity\Incoming
类的任何子类中访问。这就是twig无法访问该属性的原因


将属性
设置为公共
或在
Mail\Entity\Incoming
类中创建一个访问函数。

谢谢,属性已被公共访问。我如何创建访问器函数,是一些例子吗?