Cakephp 3.6 - 缺少控制器错误

Cakephp 3.6 - Missing Controller Error

我遇到了这个似乎没有意义的错误。我正在使用这个插件:https://github.com/hashmode/cakephp-tinymce-elfinder。我需要创建和管理路由。然而,即使 CakePHP 看到了插件,它也看不到其中的控制器。我不明白我做错了什么。

这是我/admin/elfinder的路线:

Router::prefix('admin', function ($routes) {
  $routes->connect('/elfinder', ['plugin' => 'CakephpTinymceElfinder', 'controller' => 'Elfinders', 'action' => 'elfinder']);
});

这是我正在尝试访问的controller/action

https://github.com/hashmode/cakephp-tinymce-elfinder/blob/master/src/Controller/ElfindersController.php

但我收到以下错误:

2018-06-01 15:20:33 Error: [Cake\Routing\Exception\MissingControllerException] Controller class Elfinders could not be found.
Request URL: /admin/elfinder

肯定是在找插件。为什么 CakePHP 找不到控制器?

根据官方 CookBook,您需要按以下方式配置前缀路由。希望这有帮助。

Router::plugin('YourPlugin', function ($routes) {
    $routes->prefix('admin', function ($routes) {
        $routes->connect('/:controller');
    });
});

https://book.cakephp.org/3.0/en/development/routing.html#prefix-routing

前段时间为了个人需要写了一个插件。我需要将其控制器绑定到 /shop/shop/api URL。我设法做到了这一点

Router::scope('/shop',['plugin'=>'MyPlugin'] ,function (RouteBuilder $routes) {
    $routes->prefix('api', function($routes) {
        $routes->extensions(['json']);
        $routes->connect('/:controller');

        $routes->resources('Categories');
        $routes->resources('Products');
        $routes->resources('Prices');
        $routes->resources('Pricetypes');
    });

    $routes->connect('/:controller');
    $routes->fallbacks(DashedRoute::class);
});