5

我的 symfony2 项目有以下问题:

这是我的控制器的代码

public function showCustomerAction($id) {
    // retrieve the customer from the database
    $em = $this->getDoctrine()->getManager();
    $customer = $em->getRepository('VictorIoSiteBundle:Customer')->find($id);

    //throw new \Exception($customer);
    return $this->render('VictorIoSiteBundle:Site:viewCustomer.html.twig', array('customer' => $customer));
}

我的树枝视图的代码(很简单):

{% if customer is defined %}
    <h3>Customer: {{ customer }} </h3>
{% endif %}

最后是我的 routing.yml

victor_io_site_show_customer:
pattern: /show-customer/{id}
defaults: { _controller: VictorIoSiteBundle:Site:showCustomer }
requirements:
    id: \d+

现在当我继续

http://localhost/Garage/web/app_dev.php/show-customer/46

我收到以下错误:

Variable " customer " does not exist in VictorIoSiteBundle:Site:viewCustomer.html.twig at line 2
500 Internal Server Error - Twig_Error_Runtime
4

1 回答 1

11

好像是人品问题。您的. _ 尝试删除它们并添加一个真实的空间。{{ customer }}

当你点击Alt Gr+时会出现这个字符Space(我经常发生这种情况)

提示

  • TWIG 会忽略空格,如果存在真正的空格问题,则不会导致错误
  • 大多数情况下,当你看到

    变量“foo”不存在

    foo这意味着你在变量后面有这个字符

于 2013-10-21T13:16:31.327 回答