Created
February 3, 2015 13:30
-
-
Save bravo-kernel/4ace454107afaf7279a1 to your computer and use it in GitHub Desktop.
mapResources for all Controller files found in a prefix route
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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