Redirecting in Slim 2 Middleware
I recently ran into a problem with calling redirect() in a Slim Framework 2 middleware class, so I thought I'd better document the solution so that I remember in future! The authentication middleware looks roughly like this: class Authentication extends \Slim\Middleware { public function call() { if (!$this->isLoggedIn()) { $app = \Slim\Slim::getInstance(); $app->redirect($app->urlFor('login')); } $this->next->call(); } // other methods… } The problem is that you can't call $app->redirect() in Middleware as redirect() is designed to… continue reading.