Creating cakephp route 3

Asked

Viewed 354 times

1

Intent:
access http://localhost/api/users/[action]

created the route

Router::scope('/api', function (RouteBuilder $routes) {
    $routes->extensions(['json']);
    $routes->resources('Usuarios');    
});

is working, but when I access the address http://localhost/users/[action] works the same way, I don’t want this address to be available, just the /api address

filing cabinet routes.php

Router::defaultRouteClass('DashedRoute');

Router::scope('/', function (RouteBuilder $routes) {

    $routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']);

    $routes->connect('/pages/*', ['controller' => 'Pages', 'action' => 'display']);

    $routes->fallbacks('DashedRoute');
});

 //essa é a rota que eu criei
Router::scope('/api', function (RouteBuilder $routes) {
    $routes->extensions(['json']);
    $routes->resources('Usuarios');    
});

Plugin::routes();

1 answer

1

The line $routes->resources('Usuarios'); will create all possible routes. A official documentation There are some examples of how you can limit that. Example of Cakephp documentation:

$routes->resources('Usuarios', [
    'only' => ['index', 'view']
]);

This restricts the amount of routes created, you should only want the index, so you can take the view.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.