Nico.Lbrgn Nico.Lbrgn - 5 months ago 26
PHP Question

[Symfony][Twig] - Twig display a null value while dumping the object shows a not null value

I'm on a symphony project, in development environement. I'm trying to display an object, inside a twig view. My controller get the object by querying an entity repository, and give it to the view.

This is what my object looks like when I dump it into the view with the twig {{ dump(article) }} function :

Article {#983 ▼
-id: 1
-createDate: DateTime {#1155 ▼
+"date": "2015-12-21 23:31:11.000000"
+"timezone_type": 3
+"timezone": "Europe/Berlin"
}
-updateDate: DateTime {#1063 ▼
+"date": "2016-06-13 13:30:31.000000"
+"timezone_type": 3
+"timezone": "Europe/Berlin"
}
-author: "author"
-title: "A good title"
-content: "<p>For a good content</p>"
}


I can access to all the value inside the object, except the "updateDate".
If I {{ dump(article.createDate) }}, I get this :

DateTime {#1160 ▼
+"date": "2015-12-21 23:31:11.000000"
+"timezone_type": 3
+"timezone": "Europe/Berlin"
}


and if I {{ dump(article.updateDate) }} I get this :

null


While the full object dump give me something similar than article.createDate for article.updateDate.

How can I fix that ? I need to use my article.updateDate in my twig view.

Thanks

Answer

Okay try few things:

  1. {{ updateDate }} if you pass Article object as params array from controller
  2. {{ article.getUpdateDate }} to access parameter through getter