Php – symfony2 routing with annotations not working

PHPsymfony

I just downloaded symfony2 and am beginning to play with routing via annotations. I have my app/config/routing.yml set in the bundle I created to use annotations, and have deleted the Acme bundle and all routing references to it. That said, I've tried creating a couple different route annotations in my controller like @Route("/") and @Route("/hello/{name}") but I'm always greeted with a 404 error (using the dev environment). If I add the route in routing.yml it works just fine even though the routing is configured to use annotations. For whatever reason, my annotations are seemingly being ignored.

Here is my app/config/routing.yml:

DanDefaultBundle:
  resource: "@DanDefaultBundle/Controller/"
  type:     annotation
  prefix:   /

And here is my controller method:

/**
 * @Route("/")
 * @Template()
 */
public function indexAction()
{
    return array('name' => 123);
}

I've included the Sensio\Bundle\FrameworkExtraBundle\Configuration\Route namespace – everything as far as I can tell is correct with what I've seen in the documentation. What am I overlooking that's causing symfony2 to seemingly ignore my routing annotations? Again, if I add the routes to the routing yaml everything works so my bundle is working – but annotations seem to be ignored.

Thanks!

Dan

UPDATE:
It looks like I had to add the routes to routing_dev.yml in addition to routing.yml since I was operating in the dev environment. I suppose that's so you have have different routes in-between development and production? I suppose special care will have to be taken to make sure those routes stay in sync?

Best Answer

You accidentally removed the inclusion of routing.yml from routing_dev.yml.

Related Topic