How to config restful api has many version in cakephp 3.0

646 Views Asked by At

I want to create api with link same api/v1/controller/action. But i can not config router. Please help me! Thanks you!

1

There are 1 best solutions below

1
On

You use router scopes for that:

Router::scope('/api/v1', function ($routes) {
    $routes->connect('/posts', ['controller' => 'Posts', 'action' => 'index']);
    ... // More routes here
});

Router::scope('/api/v2', function ($routes) {
    $routes->connect('/posts', ['controller' => 'Posts', 'action' => 'index_v2']);
    ... // More routes here
});