Reputation: 2103
I'm trying to generate link to URL which contains two parameters (both of those parameters are not really necessary but I do it for practice). I created custom showAction
in DiscovererController
/**
* @Route("/rivers/{river_id}/discoverers/{id}", name="discoverer_show")
* @Template
*/
public function showAction($river_id, $id){
$em = $this->getDoctrine()->getEntityManager();
$river = $em->getRepository('MyOwnBundle:River')->find($river_id);
if(!$river){
throw $this->createNotFoundException("no river with provided id");
}
$entity = $river->getDiscoverer();
return array('entity' => $entity);
}
As you can see two parameters are passed, id of the river and id of the discoverer (which is absurd but as I said, practice...). In show action of a river (/rivers/1) I decided to put following code:
<a href="{{ path('discoverer_show', {'river_id': entity.id, 'id': entity.discoverer.id})}}"><p>{{entity.discoverer.name}}</p></a>
Note that 'entity' is a river here, and river has a discoverer. Unfortunatelly, when I try to render this action, I get error which tells me that:
An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "discoverer_show" as such route does not exist.") in /path/to/project/src/My/OwnBundle/Resources/views/River/show.html.twig at line 9.
I dont have a clue what is wrong, I provided both necessary parameters and used "discoverer_show" which I defined in my controller. How to correctly render this link?
Upvotes: 0
Views: 419
Reputation: 642
A piece of advice: do not use tabs in your source code at all! Make your IDE to replace tab character with 4 spaces. This could save you a lot of trouble... Tabs does not behave well in git too.
Upvotes: 1
Reputation: 2103
Ok, by accident i figured it out. Turns out annotations in symfony2 CANNOT begin with tab.
So this thing right here is NOT going to work
/**
* @Route("/people")
*/
But this will work like a charm:
/**
* @Route("/people")
*/
Upvotes: 0