# Custom plugin doesn't work

**URL:** <https://discourse.cakephp.org/t/custom-plugin-doesnt-work/1670>\
**Category:** Plugins\
**Created:** [December 5, 2016, 1:47pm UTC](https://discourse.cakephp.org/t/custom-plugin-doesnt-work/1670 "2016-12-05T13:47:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sandra](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@Sandra](https://discourse.cakephp.org/u/Sandra)\
**Post date:** [December 5, 2016, 1:47pm UTC](https://discourse.cakephp.org/t/custom-plugin-doesnt-work/1670/1 "2016-12-05T13:47:07Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![markstory](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/markstory/32/182_2.png) [@markstory](https://discourse.cakephp.org/u/markstory)\
**Post date:** [December 5, 2016, 10:06pm UTC](https://discourse.cakephp.org/t/custom-plugin-doesnt-work/1670/2 "2016-12-05T22:06:06Z")

</div>

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

```auto
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?

---

<div class="post-metadata">

**Author:** ![Din0saur](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/din0saur/32/323_2.png) [@Din0saur](https://discourse.cakephp.org/u/Din0saur)\
**Post date:** [July 19, 2017, 8:27pm UTC](https://discourse.cakephp.org/t/custom-plugin-doesnt-work/1670/3 "2017-07-19T20:27:52Z")

</div>

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’ =\> ‘ **C** ontato’, ‘action’ =\> ‘index’));  
// Router::connect(’/’ , array(‘controller’ =\> ‘ **c** ontato’, ‘action’ =\> ‘index’));  
// Router::connect(’/Contato’ , array(‘controller’ =\> ‘ **c** ontato’, ‘action’ =\> ‘index’));  
Router::connect(’/Contato’ , array(‘controller’ =\> ‘ **C** ontato’, ‘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](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…
