我需要从symfony2访问twig中的实体.在控制器内部,我可以做一些事情:
return $this->render('frontendBundle::carrodecompras.html.twig', array(
'entity' => $entity
));
Run Code Online (Sandbox Code Playgroud)
然后在树枝上我可以用entity.name这样的方式访问实体属性.
我需要完成相同的功能,但功能 redirectToRoute()
return $this->redirectToRoute('frontend_carrodecompras', array(
'entity' => $entity,
));
Run Code Online (Sandbox Code Playgroud)
但它似乎没有用.
我收到以下错误:
第32行的frontendBundle :: carrodecompras.html.twig中不存在变量"entity"
编辑:我正在使用Symfony 2.7
变量$ entity存在(它实际上在应用程序中称为$ cortina我使用$ entity进行简化),就在redirectToRoute函数之前,我这样做是为了测试它
echo "<pre>";
var_dump($cortina);
echo "</pre>";
return $this->redirectToRoute('frontend_carrodecompras', array(
'cortina' => $cortina,
));
Run Code Online (Sandbox Code Playgroud)
结果如下:
object(dexter\backendBundle\Entity\cortina)#373 (16) {
["id":"dexter\backendBundle\Entity\cortina":private]=>
int(3)
...
Run Code Online (Sandbox Code Playgroud)
这是Twig代码:
<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',',','.') …Run Code Online (Sandbox Code Playgroud)