1
votes

Having some issues with the URL routing for my Users plugin and I can't seem to understand what is causing the issues.

So, I have baked a plugin using the cake shell (cake bake plugin Users). This has created the folder structure in plugins folder (./plugins/Users/).

I have also created the bare minimum in UsersController.php(./plugins/Users/src/Controller/UsersController.php)

<?php

namespace Users\Controller;

use Users\Controller\AppController;

class UsersController extends AppController {

    public function login() {

    }
}

My routes.php file looks like this:

Router::plugin('Users', function ($routes) {
$routes->connect('/login', [
    'controller' => 'Users',
    'action' => 'login'
], ['_name' => 'login']);
$routes->fallbacks();

});

Accessing www.examples.com/users/login I receive :

"Error: Create the class UsersController below in file: /var/www/plugins/Users/src/Controller/UsersController.php"

DebugKit error shows:

Unserializable object - Cake\Routing\Exception\MissingControllerException. Error: Controller class Users could not be found. in /var/www/vendor/cakephp/cakephp/src/Routing/Dispatcher.php, line 80

I have been toying with this for almost a day now, including consulting the CakePHP Book so any help would be appreciated if I am missing one small thing

1
Did you use bake for creating the plugin?José Lorenzo Rodríguez
@JoséLorenzo yes, I did ("cake bake plugin Users" is the full command I used)Pirouet
Did you answer "yes" when it asked to modify your composer.json file?José Lorenzo Rodríguez

1 Answers

2
votes

If you update your /composer.json

"autoload": {
    "psr-4": {
         ...
        "Users\\": "src"
    }
},

and in your /config/bootstrap.php, you have to write this

Plugin::loadAll([
  ... ,
  'Users' => ['autoload' => false, 'routes' => true, 'bootstrap' => false],
]);

and refresh your autoload file :

composer dumpautoload

does it works ?

Phil