Skip to content

Instantly share code, notes, and snippets.

@bravo-kernel
Created February 3, 2015 13:30
Show Gist options
  • Save bravo-kernel/4ace454107afaf7279a1 to your computer and use it in GitHub Desktop.
Save bravo-kernel/4ace454107afaf7279a1 to your computer and use it in GitHub Desktop.
mapResources for all Controller files found in a prefix route
/**
* Prefixed API routes (served using Crud.ApiListener).
*/
Router::prefix('api', function ($routes) {
// Enable .json extension parsing
$routes->extensions(['json', 'xml']);
// mapResources for all Controller files found in /src/Controller/Api
$dir = new Folder(APP . 'Controller' . DS . 'Api');
$controllerFiles = $dir->find('.*Controller\.php');
if ($controllerFiles) {
foreach ($controllerFiles as $controllerFile) {
$routes->resources(substr($controllerFile, 0, strlen($controllerFile) - 14));
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment