Cakephp 3.6 - 缺少控制器错误

时间:2018-06-02 02:26:22

标签: cakephp cakephp-3.0

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

这是/admin/elfinder的路线:

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

这是我试图访问的控制器/操作

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找不到控制器?

1 个答案:

答案 0 :(得分:1)

根据官方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网址。我设法像这样做了

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);
});