If you want your plugin to have and use routes, you need to configure it first - otherwise,
None of the currently connected routes match the provided parameters. Add a matching route to config/routes.php
Start by enabling routes and bootstrapping when you load the plugin in your src/Application.php:
$this->addPlugin('MyPlugin', ['bootstrap' => true, 'routes' => true]);
Create plugins/MyPlugin/config/routes.php with the following content:
<?php
use Cake\Routing\RouteBuilder;
use Cake\Routing\Route\DashedRoute;
use Cake\Routing\Router;
Router::plugin($this->getName(), function (RouteBuilder $routes) {
$routes->fallbacks(DashedRoute::class);
});
Make sure to load the above config in the plugin's plugins/MyPlugin/config/bootstrap.php:
<?php
use Cake\Core\Plugin as CorePlugin;
if (CorePlugin::getCollection()->get($this->getName())->isEnabled('routes')) {
include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'routes.php';
}
The routing inside your plugin should be working now:
\Cake\Routing\Router::url([
'prefix' => false,
'plugin' => 'MyPlugin',
'controller' => 'Users',
'action' => 'login',
]),
The above uses $this->getName() to fetch the current plugin name instead of hardcoding MyPlugin, but you can do that instead if you prefer.