简体   繁体   English

symfony2中不存在变量

[英]Variable does not exist in symfony2

I have the following problem on my symfony2 project: 我的symfony2项目有以下问题:

This is the code of my controller 这是我的控制器的代码

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));
}

And the code of my twig view (quite simple): 我的树枝视图的代码(很简单):

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

Finally my routing.yml 最后我的routing.yml

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

Now when I go on 现在,当我继续

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

I get the following error : 我收到以下错误:

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

It looks like a characters issue. 它看起来像一个角色问题。 There are fake spaces char(194) in your {{ customer }} . 您的{{ customer }}有假空格char(194)
Try just removing them and add a real space instead. 尝试删除它们并添加一个真实空间。

This character occurs when you hit Alt Gr + Space (it happens to me alot) 当你点击Alt Gr + Space时会出现这个角色(碰巧我很多)

Hints 提示

  • TWIG ignores spaces and wouldn't result in an error if there was a real space issue TWIG忽略空格,如果存在真正的空间问题,则不会导致错误
  • Mostly, when you see 大多数情况下,当你看到

    Variable "foo " does not exists 变量“foo”不存在

    it means you have this character after the foo variable 这意味着你在foo变量后面有这个字符

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM