简体   繁体   English

无法在树枝模板中呈现一些变量

[英]Can't render some variables in twig template

I've written my application using ZF2. 我已经使用ZF2编写了我的应用程序。 I have 2 modules: mail and file. 我有2个模块:邮件和文件。 All vars from mail module are rendered. 来自邮件模块的所有变量都已呈现。 Can't render object file. 无法呈现目标文件。 When I do {{ dump(mail.file) }} it returns NULL . 当我做{{ dump(mail.file) }}它返回NULL But if I do {{ dump() }} the file object does exist: 但是如果我做{{ 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)

Anyone help me? 有人帮我吗?

The file property in the Mail\\Entity\\Incoming class is protected hence it is only accessible from within the class itself or any children of the Mail\\Entity\\Incoming class. Mail\\Entity\\Incoming类中的file属性protected因此只能从该类本身或Mail\\Entity\\Incoming类的任何子级中访问。 This why twig can't access that property. 这就是为什么树枝无法访问该属性的原因。

Either make the property public or create an accessor function within the Mail\\Entity\\Incoming class. Mail\\Entity\\Incoming类中将该属性设置为public或创建访问器函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM