简体   繁体   中英

Symfony2 Array to String Doctrine value

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?

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 %}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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