MethodProg
MethodProg

Reputation: 39

I would like ArrayCollection instead of Doctrine\ORM\PersistentCollection

I've wrote in a twig view this:

{% for catalog in box.getCatalogs() %}

{% for mod in catalog.getModel() %}

{{ dump(catalog.getModel()) }}

{% endfor %}

 {% else %}
  nothing
 {% endfor %}

I get this in a dump enter image description here

So how do get an array of collection in a twig view,?

Upvotes: 0

Views: 584

Answers (1)

janh
janh

Reputation: 2972

You don't need to worry about the type of Collection object, Both ArrayCollection and PersistentCollection implement the Collection interface and work the same way. The difference is that PersistentCollection contains objects that have been persisted in the DB and might hit the database when you iterate over them.

If you use type-hinting, just hint at Doctrine\Common\Collections\Collection.

If you write

{% for mod in catalog.getModel() %}
    {{ dump(mod) }}
{% endfor %}

in your twig template, you should see your objects.

Upvotes: 1

Related Questions