Symfony2 Basic routing

From WikiOD

Annotation-based routing[edit | edit source]

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):

    resource: "@AppBundle/Controller"
    type:     annotation

YAML routes[edit | edit source]

Instead of annotations, you can also specify your routes as YAML:

    path: /index
    defaults: { _controller: AppBundle:Acme:index }

The same options apply to both annotations and YAML configurations. To import a YAML routing configuration in your root routing configuration, you don't need to specify a type:

    prefix: /app
    resource: "@AppBundle/Resources/config/routing.yml"