I want to be able to support multiple versioned endpoints from my api simultaneously, such as:
/api/v1.1/counties/get
/api/v1.2/counties/get
But in trying to implement the routing for this, a bit perplexed as to how Cake wants this as I keep getting a
Error: Controller class Counties could not be found.
Attempt 1:
Router::scope('/api', function ($routes) {
$routes->setExtensions(['json']);
$routes->fallbacks('DashedRoute');
$versions = [
1.1
];
foreach ($versions as $version) {
$routes->scope('/' . $version, function($routes) {
$routes->resources('Counties', [
'controller' => 'Counties',
'prefix' => 'api',
'map' => [
'get' => [
'action' => 'get',
]
]
]);
}
}
});
Attempt 2:
Router::scope('/api', function($routes) {
$routes->scope('/v1.1', function($routes) {
$routes->resources('Counties', [
'controller' => 'Counties',
'map' => [
'get' => [
'action' => 'get'
]
]
]);
});
$routes->connect(
'/v1.1/counties/get',
[
'controller' => 'Counties',
'action' => 'get',
]
);
});
The directory structure I'm currently using (which is still open for debate):
src/Controller/Api/V1.1, which would use base controllers from src/Controller/Api and extend them with stub methods to override if needed. Most of my "fat" is in the models.
and src/Controller/Api/V1.1/CountiesController.php has:
namespace App\Controller\Api\V1.1;
class CountiesController extends AppController
{
}
Would appreciate any insight