Creating cakephp route 3

0

Intention:
access link

I created the route

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

is working, but when I access the address link works the same way, I do not want this address to be available, just the / api address

file 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();
    
asked by anonymous 17.07.2016 / 09:04

1 answer

0

The $routes->resources('Usuarios'); line will create all possible routes. The official documentation has some examples of how you can limit this. Example CakePHP documentation:

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

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

    
18.07.2016 / 03:33