Is there some pattern of routes and how to write the structure using SlimPhp?
Like, I made a api folder with a index.php to store ALL my routes:
$app
I usually have my own router before I involve Slim's router to determine which route to use based on the path after the domain:
public/index.php
chdir(dirname(__DIR__));
require_once 'vendor/autoload.php';
$app = new Slim\App;
require 'app/routes/index.php';
$app->run();
app/routes/index.php
$_url = parse_url($_SERVER['REQUEST_URI']);
$_routes = explode('/',$_url['path']);
$_baseRoute = $_routes[1];
switch ($_baseRoute) {
case 'api':
$_routeFile = 'app/api/' . $_routes[2] . '.php';
break;
default:
$_routeFile = 'app/routes/' . $_baseRoute . '.php';
break;
}
if (file_exists($_routeFile)) {
require $_routeFile;
}
else {
die('Invalid API request');
}