Reputation: 13
For some reason I can't get the routes to work with annotations. Here is the code I tried.
<?php
use Symfony\Component\HttpFoundation\Response;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
/**
* Class PostsController
*/
class PostsController
{
/**
* @Route('forum/posts', 'bd_forum_posts')
*/
public function indexAction()
{
return new Response('Hello from PostsController');
}
}
When I try to access http://127.0.0.1:8000/forum/posts
I get route not found
The path forum/posts is not displayed on console router:debug output too
Upvotes: 1
Views: 162
Reputation: 692
Have you set app/config/routing.yml correctly? It should be like this:
vendor_bundle:
resource: "@VendorXYBundle/Controller/"
type: annotation
prefix: /
Then, the format for routing should be this:
/**
* @Route('/forum/posts', name='bd_forum_posts')
*/
Note the starting slash in the route and the name property.
...and don't forget to namespace your controller correctly. It should be under Vendor\XYBundle\Controller.
Upvotes: 2