I have the following problem on my symfony2 project:
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
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 }}
.Try just removing them and add a real space instead.
This character occurs when you hit Alt Gr + Space (it happens to me alot)
Hints
Mostly, when you see
it means you have this character after the
foo
variable