Silex
Silex copied to clipboard
Middleware After/Before with mount()
I want to attach middleware to group routes, i write this, for example:
$app->mount("/profile", function ($profile) {
$profile->get("/", "App\\Controllers\\IndexController::profile");
})
->before(new AuthMiddleware())
->after(new AfterMiddleware());
This generate an error:
Fatal error: Call to a member function after() on null in
.../app/routes.php on line 23
where did I go wrong?
you need to attach the middleware's to the $profile controller collection I'm pretty sure instead of the $app
$app->mount("/profile", function ($profile) {
$profile->get("/", "App\\Controllers\\IndexController::profile");
$profile->before(new AuthMiddleWare())->after(new AfterMiddleware());
});