Is it possible to do routing scope inheritance in CakePHP3?

28 Views Asked by At

I'm doing a big refactoring and i want to add some scope inside my app but i'm stuck on this problem:

I have a main scope "/api" and i want to have a sub-scope inside named "/user", is it possible in CakePHP3 ?

Here is my code:

Router::scope('/api', function ($routes) {
    //USERS
    Router::scope('/user', ['controller' => 'Users'], function ($routes) {
        $routes->connect('/saveUser', ['action' => 'save']);
        $routes->connect('/editUser/:id', ['action' => 'edit'])
            ->setPass(['id'])
            ->setPatterns(['id' => '\d+']);
        $routes->connect('/deleteUser/:id', ['action' => 'delete'])
            ->setPass(['id'])
            ->setPatterns(['id' => '\d+']);
        $routes->connect('/deleteUser/:id/deleteImage', ['action' => 'deleteImage'])
            ->setPass(['id'])
            ->setPatterns(['id' => '\d+']);
    });
});

The error page say "Missing Method in ApiController, The action users is not defined in ApiController" but i'm calling UsersController.

Thanks for help

[SOLVED]

Router::scope('/api', function ($routes) {
    //USERS
    $routes->scope('/user', ['controller' => 'Users'], function ($innerRoutes) {
        $innerRoutes->connect('/saveUser', ['action' => 'save']);
        $innerRoutes->connect('/editUser/:id', ['action' => 'edit'])
            ->setPass(['id'])
            ->setPatterns(['id' => '\d+']);
        $innerRoutes->connect('/deleteUser/:id', ['action' => 'delete'])
            ->setPass(['id'])
            ->setPatterns(['id' => '\d+']);
        $innerRoutes->connect('/deleteUser/:id/deleteImage', ['action' => 'deleteImage'])
            ->setPass(['id'])
            ->setPatterns(['id' => '\d+']);
    });
});
0

There are 0 best solutions below