Вопрос

If I get an array of types using Doctrine like this:

$types = $this->getDoctrine()
    ->getRepository('Model:Type')
    ->findAll();

And then pass $types to the Twig template (as 'types') and loop through it:

{% for type in types %}
-- WHAT GOES HERE?
{% endfor %}

I've been doing a bit of reading, and I'm not even sure if this is possible? Can I only pass associative arrays through to Twig or do arrays of objects work? And if so, how can I access the public functions of the object in Twig?

Basically I want to call getName(), getUsage(), getId() and a few other public functions on the Type object.

Thanks

Это было полезно?

Решение

Then you could do it like below:

{% for type in types %}
  {{ type.name }}
  {{ type.usage }}
  {{ type.id }}
{% endfor %}

{{ type.getName() }} also works, it's same with {{ type.name }}.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top