Everything written by nifr is true, but it really doesn't help you.
Symfony is built in a router designed to support βstaticβ routes, so when the cache is first warmed up, routes will be generated and cached. If you check the specified cache files, you will see that the routes are stored in a static private variable.
There is no easy way to update a route (or change routes).
If you check the CacheClearCommand , you will see that the implementation is quite complicated. Some suggest deleting the entire cache directory, which I do not recommend, it is quite heavy and causes your site to freeze until the cache is regenerated (even you can get exceptions for missing files / and logged out users if sessions stored in the folder with cache)
Calling cache leak mode is not possible if the cache is already delegated.
If you just delete the two related cache files and then call warmUp on the router, this would be a better solution, but also not a pleasant one.
$cacheDir = $this->container->getParameter("kernel.cache_dir"); // Delete routing cache files $filesystem = $this->container->get('filesystem'); $finder = new Finder(); /** @var File $file */ foreach ($finder->files()->depth('== 0')->in($cacheDir) as $file) { if (preg_match('/UrlGenerator|UrlMatcher/', $file->getFilename()) == 1) { $filesystem->remove($file->getRealpath()); } } $router = $this->container->get('router'); $router->warmUp($cacheDir);
- Override the default router class
Starting from 2.8, the Router class is defined by the router.class parameter . See here: https://github.com/symfony/framework-bundle/blob/v2.8.2/Resources/config/routing.xml#L63
Add something like this to your config.yml
parameters: router.class: "My \ Fancy \ Router"
You can implement your own router class by extending the source router, and you also need to extend the UrlMatcher and UrlGenerator classes to call the parent implementation and add your own routes to map to / generate. This way you do not need to update the cache, as you can dynamically add your routes.
Note. I'm not sure that you can rely on this in the long run, if you check the wizard, the definition has changed, the parameter no longer exists:
https://github.com/symfony/framework-bundle/blob/master/Resources/config/routing.xml#L54