5
存在我已經在我的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));
}
的代碼和我的樹枝視圖的代碼(很簡單):
{% 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
非常感謝後,這個角色!你解決了我的問題。 – Victor