Javier Núñez Fernández Full Stack Web Engineer

Symfony2: annotations VS yaml

When we have to map a doctrine entity, we have to establish a new route or we have to establish a new lifecycle callback in our Symfony2 project, we have to made a choose, what technique will we use? We have two options (XML and YAML are considered the same technique with different markup languages):

In both cases, we have to enable the routings of our App Controller by including them in app/config/routing.yml:


# import routes from a controller class
post:
    resource: "@SensioBlogBundle/Controller/PostController.php"
    type:     annotation

* In case of YML we don't have to explicit set type property

Fabien Potencier (Symfony's Founder) prefer annotations and he gives his opinion in an article.

I don't think one of this techniques is better than the other, just take the one you prefer