1

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

4
  • Can you update with the Twig you are using to generate that? I'd expect {{ createDate }} not to contain anything by default. Rather {{ article.createDate }} to contain the createDate data for that object. Commented Jun 14, 2016 at 19:45
  • 1
    This is very strange.. I think you need to show us some more information, like your action method, entity, your repository method and so on.. Commented Jun 15, 2016 at 6:29
  • try this {{article.updateDate|date("Y-m-d H:i:s")}} Commented Jun 15, 2016 at 8:55
  • It's what I try for display it, but it return me the date at the moment, cause the var associate to the filter is null Commented Jun 15, 2016 at 9:18

2 Answers 2

2

Okay try few things:

  1. {{ updateDate }} if you pass Article object as params array from controller
  2. {{ article.getUpdateDate }} to access parameter through getter
Sign up to request clarification or add additional context in comments.

Comments

0

Thanks Ignas,

I tried with the getter and it worked good. I did not know that I can use getter in the view, but it's so logical ...

I think I will use only getters in the view now, I found this more logic as my entity attributes are defined in private ...

Thanks all for your help !

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.