1
votes

I have this function on a repository:

public function getSolicitudes($usuario_id)
{
    $qb = $this->getEntityManager()->createQueryBuilder();

    $qb
            ->select('su.id, su.fecha_creacion, tt.nombre AS tipo_tramite, tr.nombre AS tipo_registro, es.nombre AS estado_solicitud')
            ->from("ComunBundle:SolicitudUsuario", "su")
            ->where('su.usuario = :usuario_id')
            ->join('su.tipo_tramite', 'tt', \Doctrine\ORM\Query\Expr\Join::INNER_JOIN)
            ->join('su.tipo_registro', 'tr', \Doctrine\ORM\Query\Expr\Join::INNER_JOIN)
            ->join('su.estado_solicitud', 'es', \Doctrine\ORM\Query\Expr\Join::INNER_JOIN)
            ->orderBy('su.fecha_creacion', 'DESC')
            ->setParameter('usuario_id', $usuario_id);

    return $qb->getQuery()->getResult();
}

In Twig template I have this:

{{ entities|ladybug_dump }}

And the output is something like image show:

enter image description here

I'm trying to iterate over the result in Twig template as follow:

{% for solicitud in entities %}
    <tr>
        <td></td>
        <td>{{ solicitud.tramite }}</td>
        <td>{{ solicitud.id }}</td>
        <td>{{ solicitud.solicitud }}</td>
        <td>{{ solicitud.estado }}</td>
        <td>{{ solicitud.fecha }}</td>
        <td></td>
    </tr>
{% endfor %}

But I got this error:

Key "tramite" for array with keys "id, fecha_creacion, tipo_tramite, tipo_registro, estado_solicitud" does not exist in /var/www/html/src/RPNIBundle/Resources/views/Listado/index.html.twig at line 25

What I'm missing here?

1

1 Answers

3
votes

It's obvious, you're using the wrong key, as the exception suggests:

Key "tramite" for array with keys "id, fecha_creacion, tipo_tramite, tipo_registro, estado_solicitud" does not exist in /var/www/html/src/RPNIBundle/Resources/views/Listado/index.html.twig at line 25

Your object has a tipo_tramite key, not tramite. You should change the output statements.