# Routing to plugin using prefix error: Missing Controller

**URL:** <https://discourse.cakephp.org/t/routing-to-plugin-using-prefix-error-missing-controller/11208>\
**Category:** Need Help\
**Created:** [May 11, 2023, 2:05pm UTC](https://discourse.cakephp.org/t/routing-to-plugin-using-prefix-error-missing-controller/11208 "2023-05-11T14:05:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Onnet](https://avatars.discourse-cdn.com/v4/letter/o/34f0e0/32.png) [@Onnet](https://discourse.cakephp.org/u/Onnet)\
**Post date:** [May 11, 2023, 2:05pm UTC](https://discourse.cakephp.org/t/routing-to-plugin-using-prefix-error-missing-controller/11208/1 "2023-05-11T14:05:30Z")

</div>

Hi

I got “Missing Controller” though the controller class seems to be found by Router and the controller exits.  
When the url is **/admin/stats/contenus** , i want to reach the action=\> **contenus** in the **StatistiquesController.php** in my plugin=\> **Statistics** using prefix=\> **admin**.  
In Application::bootstrap  
$this-\>addPlugin(‘Statistics’);

In my main project route.php:

```auto
    $routes->prefix('admin', function (RouteBuilder $builder) {
        .../...
        /* Option 1 */
        $builder->connect('/stats/*', ['plugin' => 'Statistics', 'controller' => 'Statistiques', 'prefix' => false]);

        $builder->fallbacks(DashedRoute::class);
    });

    /* Option 2 */
    $routes->prefix('/admin/stats', function (RouteBuilder $builder) {
        $builder->connect('/*', ['plugin' => 'Statistics', 'controller' => 'Statistiques', 'prefix' => false]);
    });

    /* Option 3 */
    $routes->scope('/admin', function (RouteBuilder $builder) {
        $builder->connect('/stats/*', ['plugin' => 'Statistics', 'controller' => 'Statistiques', 'prefix' => false]);
    });

```

In my plugins/Statistics/src/Controller/StatistiquesController.php

```auto
    <?php
    declare(strict_types=1);
    namespace Statistics\Controller;
    use Statistics\Controller\AppController;
    class StatistiquesController extends AppController
    {
        public function contenus(): void
        {
        }
    }

```

None of the options above work.  
When I type following url “[http://localhost:8765/admin/stats/contenus](http://localhost:8765/admin/stats/contenus)”  
I get the following error:  
_Create the class StatistiquesController below in file: W:\WORK-CK4/plugins/Statistics/src\Controller\StatistiquesController.php_

My controller exists in the location and has the right name.  
What am I missing?

Thx for help.

---

<div class="post-metadata">

**Author:** ![ADmad](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/admad/32/20_2.png) [@ADmad](https://discourse.cakephp.org/u/ADmad)\
**Post date:** [May 11, 2023, 4:48pm UTC](https://discourse.cakephp.org/t/routing-to-plugin-using-prefix-error-missing-controller/11208/2 "2023-05-11T16:48:00Z")

</div>

> i want to reach the action=\> **contenus** in the **StatistiquesController.php** in my plugin=\> **Statistics** using prefix=\> **admin**.

Then why are you using `'prefix' => false` when connecting the routes?

Also if you want to use `admin` as prefix then your controller need to be under the namespace `namespace Statistics\Controller\Admin;`.

---

<div class="post-metadata">

**Author:** ![Onnet](https://avatars.discourse-cdn.com/v4/letter/o/34f0e0/32.png) [@Onnet](https://discourse.cakephp.org/u/Onnet)\
**Post date:** [May 12, 2023, 10:06am UTC](https://discourse.cakephp.org/t/routing-to-plugin-using-prefix-error-missing-controller/11208/3 "2023-05-12T10:06:55Z")

</div>

Thx for answer

This is not exactly what I want (forget about prefix).  
my url: /admin/stats/contenus  
should fire ==\> plugin=Statistics, controller=Statistiques, action=contenus  
because I already use admin for the authenticated part of my app.

I created the suggested controller at the right location with the right namespace with the suggested code (that is exactly what I expected) but the controller can’t be found!

The error dump shows  
object(Cake\Http\ServerRequest) id:0 {

This seems to be what I want, but the controller is missing…

All the tries I made for route.php lead to the same error and the same suggestion.

I’ve seen the same issue on Stack Overflow ( [php - CakePHP 4 can’t load plugin’s controller - Stack Overflow](https://stackoverflow.com/questions/70041506/cakephp-4-cant-load-plugins-controller?newreg=39125d18e1d14428b4230955170b3c60) )  
but nobody has answer since 1,5 year.

---

<div class="post-metadata">

**Author:** ![Kaiser85](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kaiser85/32/2714_2.png) [@Kaiser85](https://discourse.cakephp.org/u/Kaiser85)\
**Post date:** [May 15, 2023, 2:28pm UTC](https://discourse.cakephp.org/t/routing-to-plugin-using-prefix-error-missing-controller/11208/4 "2023-05-15T14:28:56Z")

</div>

First option should work but you need to remove `'prefix' => false `. Tested on my local env and it worked using a plugin. And each time i added `'prefix' => false ` gave the same error you have
