Reputation: 381
I have a problem with an error when I print in twig file the value of a doctrine query..
In my controller I have this code in a for loop, to get more elements from my database:
$pyramid[$x]['id_user'] = $queryconteggio;
And if I print with dump function I receive more array for 1 user now:
array(2) { [0]=> array(1) { [1]=> string(2) "94" } [1]=> array(1) { [1]=> string(3) "103" } }
And now for another user:
array(1) { [0]=> array(1) { [1]=> string(3) "101" } }
The values are accurate but when I print without dump:
{{ pyramid.id_user }}
It gives me this error:
An exception has been thrown during the rendering of a template ("Notice: Array to string conversion") in DtEcBundle:Profilo:digitalpr-profile.html.twig at line 53.
At the line 53 there is this code in a for: {{ pyramid.id_user }}
How can I print the value of my arrays without error?
Upvotes: 1
Views: 567
Reputation: 11351
pyramid.id_user
is not a string but rather an array of arrays of strings, all with key "1". To print it you need to do something like:
{% for id in pyramid.id_user %}
{{ id[1] }}
{% endfor %}
Upvotes: 2