Importing Routes from a Controller

This is how you import routes from a specific controller (only works if you used annotations):

whatever_routes:
    resource: "@MyBundle/Controller/WhateverController.php"
    type:     annotation

This is very useful if you have multiple controllers in single bundle but you can’t import the whole Controller directory at once because some routes have to be treated in a special way, e.g. you want a different prefix for every controller.

whatever_routes:
    resource: "@MyBundle/Controller/WhateverController.php"
    prefix:   /some-bundle/whatever
    type:     annotation

other_routes:
    resource: "@MyBundle/Controller/AnotherController.php"
    prefix:   /some-bundle/another
    type:     annotation

For reference, this is the original documentation of that feature.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.