小编Vic*_*tor的帖子

symfony2中不存在变量

我的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));
}
Run Code Online (Sandbox Code Playgroud)

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

{% if customer is defined %}
    <h3>Customer: {{ customer }} </h3>
{% endif %}
Run Code Online (Sandbox Code Playgroud)

最后我的routing.yml

victor_io_site_show_customer:
pattern: /show-customer/{id}
defaults: { _controller: VictorIoSiteBundle:Site:showCustomer }
requirements:
    id: \d+
Run Code Online (Sandbox Code Playgroud)

现在,当我继续

http://localhost/Garage/web/app_dev.php/show-customer/46
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Variable " customer " does not exist in VictorIoSiteBundle:Site:viewCustomer.html.twig at line 2
500 Internal Server Error - Twig_Error_Runtime
Run Code Online (Sandbox Code Playgroud)

php symfony twig

5
推荐指数
1
解决办法
8686
查看次数

标签 统计

php ×1

symfony ×1

twig ×1