Chriss Baumfleisch
Chriss Baumfleisch

Reputation: 177

Advanced cakephp routes

When I have a route like this:

Router::prefix('api', function (RouteBuilder $routes) {        
    $routes->resources('Offers', function ($routes) {
        $routes->resources('SomeRelation', [
            'inflect' => 'dasherize',
            'path' => 'content',
        ]);
    });
});

I can access the page like this /api/offers/148714/content

This will redirect the URL to the index() action of my SomeRelation controller.

How can I change the action from index to any other action in the same controller?

I tried to change it according to the cake manual but either it doesn't work with my case or I didn't get the structure right

Upvotes: 0

Views: 29

Answers (1)

Chriss Baumfleisch
Chriss Baumfleisch

Reputation: 177

After fiddling around with the route I came up with the solution. Maybe it helps others.

Router::prefix('api', function (RouteBuilder $routes) {        
    $routes->resources('Offers', function ($routes) {
        $routes->resources('SomeRelation', [
            'inflect' => 'dasherize',
            'path' => 'content',
            'actions' => ['index' => 'view'],
        ]);
    });
});

Upvotes: 0

Related Questions