简体   繁体   中英

Symfony routing - annotations

I recently looked into the Symfony framework as I'd like to use it for some projects, however noticed that the routing is extremely awkward to use due to something called "annotations" which are basically comments above each controller method.

Is it possible to create a routes.php file and use that to overwrite the routing and completely disable these annotations? As I would like all routes in one file so it is much more flexible and maintainable.

Annotations (for routing but also for other configurations) are absolutely not mandatory in Symfony. As you can see in the docs, you can use YAML to define your routes. Anyway, using annotations is a best practice and I advice you to use them, since it's more immediate to get what route is bound to an action. You can always get a list of all routes with debug:routing command

You can use xml, yaml, php or annotation for route definitions. You just need to change this line in app/config/config.yml from

framework:
    router:
        resource: "%kernel.root_dir%/config/routing.yml"

to

framework:
    router:
        resource: "%kernel.root_dir%/config/routing.php"

create app/config/routing.php and remove app/config/routing.yml

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM