I need to access an entity in twig from symfony2. Inside the controler, I can do something as:
return $this->render('frontendBundle::carrodecompras.html.twig', array(
'entity' => $entity
));
And then in twig I can access the entity properties with entity.name
and such.
I need to accomplish the same thing but with the function redirectToRoute()
return $this->redirectToRoute('frontend_carrodecompras', array(
'entity' => $entity,
));
But it doesn't seem to work.
I'm getting the following error:
Variable "entity" does not exist in frontendBundle::carrodecompras.html.twig at line 32
EDIT: I'm using Symfony 2.7
The variable $entity exists (it's actually called $cortina in the app I was using $entity for simplification), just before the redirectToRoute function I did this to test it
echo "<pre>";
var_dump($cortina);
echo "</pre>";
return $this->redirectToRoute('frontend_carrodecompras', array(
'cortina' => $cortina,
));
And the result is this:
object(dexter\backendBundle\Entity\cortina)#373 (16) {
["id":"dexter\backendBundle\Entity\cortina":private]=>
int(3)
...
This is the Twig code:
<tr>
{% set imagentela = "img/telas/" ~ cortina.codInterno ~ ".jpg" %}
<td><img src="{{ asset(imagentela | lower ) }}" alt="" width="25" height="25">
</td>
<td>{{ cortina.nombre }}</td>
<td>{{ "$" ~ cortina.precio|number_format('0',',','.') }}</td>
</tr>