cakephp: Nested prefixes cause controller not found issues

This is a (multiple allowed):

  • bug

  • enhancement

  • feature-discussion (RFC)

  • CakePHP Version: 3.4

  • Platform and Target: mac osx sierra.

What you did

I decided to follow Rest api in minutes as I always do for my api projects. This time I decided to have nested prefixes to version my api. Like this

    Router::prefix('api', function(RouteBuilder $routes){
        $routes->extensions(['json','xml']);
        $routes->prefix('v1', function(RouteBuilder $routes) {
            \\.... resources
         }
    }

When I create the ‘token’ action in my users controller and try to call the api to it, I get

controllerV1 could not be found

I then decided to map the resource in the routes like this:

    $routes->resources('Users', [
            'map' => [
                'token' => [
                    'action' => 'token',
                    'method' => 'POST'
                ]
            ]
        ]);

That solved this issue. But I have never had to do that with any of my other APIs. I then decided to implement Https middleware. To test that actions are being redirected to https by going to http, I get the same error as above:

controllerV1 could not be found

Was there a recent change that would have caused this?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 24 (24 by maintainers)

Most upvoted comments

An idiot is one who repeats the same behavior expecting a different result. That is not you 👍