cakephp: Duplicate Named Route for plugin
This is a (multiple allowed):
-
bug
-
enhancement
-
feature-discussion (RFC)
-
CakePHP Version: 3.6.4
What you did
load plugin with routes in bootstrap
Plugin::load('I18nUrl', ['routes' => true]);
call Plugin::routes() at the end of config/routes.php in base app
create a route in plugin
use Cake\Routing\Router;
use Cake\Routing\RouteBuilder;
Router::plugin('Backend', ['path' => '/gestion'], function (RouteBuilder $routes) {
$routes->connect('/', ['controller' => 'Dashboard', 'action' => 'index'], ['_name' => 'backend.dashboard']);
});
What happened
Cake\Routing\Exception\DuplicateNamedRouteException
Error: A route named "backend.dashboard" has already been connected to "/gestion".
What you expected to happen
no duplicate routes
where to search
It’s look like the RoutingMiddleware now check if $this->app is instance of PluginApplicationInterface
the src/Application extends BaseApplication which implement PluginApplicationInterface SO the standard application build plugin routes twice, first via application and bootstrap, second time via the RoutingMiddleware::prepareRouteCollection()
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 18 (18 by maintainers)
Commits related to this issue
- Deprecate Plugin::routes() I missed this earlier as I had updated my applications and removed this line. With this method undeprecated plugins will have their routes loaded twice. Once by Application... — committed to cakephp/cakephp by markstory 6 years ago
- Fix duplicate route errors when using loadPlugin() Use the plugin object to load plugin routes. This allows us to disable the hook method so that it is not triggered again. There is still a scenario... — committed to cakephp/cakephp by markstory 6 years ago
You should remove the
Plugin::routes()call in your routes file. It is only necessary if you are using the deprecated Dispatcher classes.@mirko-pagliai a PR now is open for this problem https://github.com/cakephp/cakephp/pull/12245