Custom plugin doesn't work

Hi everyone.

I’m using Cakephp 3 y I created a plugin named Intranet using bake:

bin/cake bake plugin Intranet

This structure was created:

project/plugins/Intranet

After that I created a Products controller:

bin/cake bake controller --plugin Intranet Products

In config/bootstrap.php file of my project I added:

Plugin::load('Intranet', ['bootstrap' => false, 'routes' => true]);

And in config/routes.php:

Plugin::routes();

In project/plugins/Intranet/config/routes.php file I had the next:

Router::plugin(
    'Intranet',
    ['path' => '/intranet'],
    function (RouteBuilder $routes) {
        $routes->fallbacks(DashedRoute::class);
    }
);

And in project/plugins/Intranet/composer.json:

"autoload": {
        "psr-4": {
            "Intranet\\": "src"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Intranet\\Test\\": "tests",
            "Cake\\Test\\": "./vendor/cakephp/cakephp/tests"
        }
    }

But when I access to http://site/intranet/products/index I get this error:

A route matching “array ( ‘controller’ => ‘users’, ‘action’ => ‘login’, ‘prefix’ => ‘admin’, ‘_mobile’ => false, ‘preview’ => false, ‘plugin’ => ‘Intranet’, ‘_ext’ => NULL, )” could not be found.

Can someone help me to identify the error? I tried other ways like write:

Plugin::load('Intranet', ['autoload' => true, 'bootstrap' => false, 'routes' => true]);

Also I tried to write the route in routes.php project file and execute the commands:

composer update y composer dumpautoload

without results.

Regards and thanks. Sorry, my English is very bad.

Your plugin routes file doesn’t define any routes that could match the array of

array( 
'controller' => 'users',
'action' => 'login',
'prefix' => 'admin',
'mobile' => false,
'preview' => false,
'plugin' => 'Intranet', 
'ext' => NULL,
)

as there is no prefix scope defined. Does that error contain a stacktrace?

I’m facing the a problem which I think is identical. Follow the same steps, but I have few differences:

  • Plugin name is “Aplicar/ContatoHandler”
  • plugin router is
    Router::plugin(
    ‘ContatoHandler’, // I tried ‘Aplicar/ContatoHandler’,
    [‘path’ => ‘/aplicar/contato-handler’], // i tried [‘path’ => ‘/contato-handler’],
    function (RouteBuilder $routes) {
    // versions I tried
    // nothing (no Router::connect at all)
    // Router::connect(’/’ , array(‘controller’ => ‘Contato’, ‘action’ => ‘index’));
    // Router::connect(’/’ , array(‘controller’ => ‘contato’, ‘action’ => ‘index’));
    // Router::connect(’/Contato’ , array(‘controller’ => ‘contato’, ‘action’ => ‘index’));
    Router::connect(’/Contato’ , array(‘controller’ => ‘Contato’, ‘action’ => ‘index’));
    $routes->fallbacks(DashedRoute::class);
    }
    );

Since I have existent tables and this one is “contato” and not “contatos”, I put at plugins bootstrap.php
the line:
Inflector::rules(‘uninflected’, [‘Contato’]);

Plugin is load in app/bootstrap.php with
Plugin::load(‘Aplicar/ContatoHandler’, [‘bootstrap’ => true, ‘routes’ => true]);

and app/config/routes has
Plugin::routes();

Beside that, I put the command
error_log( $_SERVER[‘REQUEST_URI’]);

So I can tell that when I call
http://localhost/ContatoHandler/Contato

a redirect to / occurs since the error log shows

[19-Jul-2017 20:24:11 UTC] /ContatoHandler/Contato
[19-Jul-2017 20:24:12 UTC] /

Thanks for any help on this…