尝试Router::promote()
:
Router::promote()
将路由(默认情况下,最后添加的)提升到列表的开头
如果我正确理解了您的问题,那么您只想覆盖一条路线。在您的app/Config/routes.php
中,添加被覆盖的路由和之后的提升CakePlugin::routes();
//.... your routes....
//Here the plugin routes being loaded
CakePlugin::routes();
//Overwrite route:
Router::connect('/accessDenied', array('plugin' => 'usermgmt', 'controller' => 'users', 'action' => 'accessDenied'));
Router::promote(); //and promote it
这应该够了吧。提升只是将最后一条路线移到顶部。在 CakePHP 中,路由以先到先服务的方式工作(如果您仔细检查源代码,它是一个数组),因此提升会将您最后定义的路由移到顶部,从而覆盖插件中定义的路由。
编辑
如果不喜欢推广,也可以先 CakePlugin::routes()
定义路由。这也应该可以解决问题。