Kiet Phan
Kiet Phan

Reputation: 11

How to config restful api has many version in cakephp 3.0

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

Upvotes: 1

Views: 632

Answers (1)

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
});

Upvotes: 4

Related Questions