symfony2 Basic routing Annotation-based routing

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

By default, all the controllers you generate with Symfony's built-in generate:controller command will make use of Symfony annotations for routing:

namespace AppBundle\Controller;

// You have to add a use statement for the annotation
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

class AcmeController
{
    /**
     * @Route("/index")
     */
    public function indexAction()
    {
        // ...
    }
}

In order for the framework to handle these routes, you need to import them in your routing.yml as follows (notice the annotation type):

app:
    resource: "@AppBundle/Controller"
    type:     annotation


Got any symfony2 Question?