kormik kormik - 5 months ago 10
PHP Question

How to add route to a controller in custom directory?

In Symfony 3 I am trying to load routing from controllers which are not in a bundle using a directory path, but parameter

%kernel.root_dir%
is not resolved here. It works if I use absolute path.

My routing.yml file:

mymodule:
resource: '%kernel.root_dir%/../src/MyModule/Controller'
type: annotation
prefix: /mymodule


Do you have any suggestion how to use relative path without referencing a bundle?

Answer

You can use a path relative to the current config file:

resource: ../../src/MyModule/Controller