I've defined my routes.ini
file with several entries like this:
[routes]
GET /=PublicController->home
GET /login=PublicController->login
GET /logout=PublicController->logout
POST /auth=PublicController->auth
[...]
I was wondering if it's possibile to dynamically modifiy routes depending on arbitrary conditions to check, e.g. session variables and so on.
Is there a way to do something like:
if ($f3->get('SESSION.user.level') == 'admin') {
GET /=AdminController->home
} else {
GET /=UserController->home
}
within an .ini file?
No. But surprisingly you can use php for this:
if ($f3->get('SESSION.user.level') == 'admin') {
$f3->route('GET /','AdminController->home');
$f3->config('admin.ini');
} else {
$f3->route('GET /','UserController->home');
}