skip to Main Content
+971 55 881 1725 hmimthiaz @ imthi.com

Symfony: Adding custom route by code during runtime

During development we always come across situation where you need to add custom routes based on some settings based from the user. In this case we cannot use any of the standard methods like annotation and configuration files in symfony.

In this case you need to use a services and hooks to inject your custom route rules during runtime.

1) In your bundles under Resources\Config\services.yml add the following

2) Now we need to create a class RoutingService.php

3) Now in your main routing.yml please include these lines

4) Once you are done please make sure you clear cache both env

5) Now the custom route should be loaded in.. Please make sure if you add more routes make sure the cache is cleared.

Leave a Reply

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

Back To Top