Mufanu
Mufanu

Reputation: 534

Can't render some variables in twig template

I've written my application using ZF2. I have 2 modules: mail and file. All vars from mail module are rendered. Can't render object file. When I do {{ dump(mail.file) }} it returns NULL. But if I do {{ dump() }} the file object does exist:

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?

Upvotes: 1

Views: 1144

Answers (1)

Tomdarkness
Tomdarkness

Reputation: 3820

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. This why twig can't access that property.

Either make the property public or create an accessor function within the Mail\Entity\Incoming class.

Upvotes: 2

Related Questions