Get the current plugin name in CakePHP

in CakePHP


If you need the current plugin name in e.g. config/routes.php or config/bootstrap.php, and don't want to hardcode it by hand, you can use $this->getName() instead. Example:

Router::plugin($this->getName(), function (RouteBuilder $routes) {
    $routes->fallbacks(DashedRoute::class);
});

The above is effectively the same as:

Router::plugin('MyPlugin', function (RouteBuilder $routes) {
    $routes->fallbacks(DashedRoute::class);
});
#cakephp #cakephp-plugin-development