Problem with $app->redirect

have a problem with Slim V2. The problem is that i can’t redirect to my dashboard page after login.

this is my index.php code:

    require_once 'vendor/autoload.php';
    //Inizio le inclusioni necessarie


    $db = new Dabble\Database(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
    global $db;

    $app = new \Slim\Slim(array(
        'templates.path' => './template',
        'debug' => true


    require 'app/GeCo.php';



And this is GeCo.php markup:


    use login\Login;

    $app->get('/', function () use ($app) {



    $app->get('/login', function () use ($app) {

        $page = 'login.php';


    $app->get('/dashboard', function () use ($app) {

        $page = 'dashboard.php';


    $app->post('/login', function () use ($app,$db) {

        try {

            $username = $_POST['username'];
            $password = $_POST['password'];

            $login = new Login($db);
            $result = $login->checkLogin($username,$password);

        }catch (\Exception $e) {
            error_log(json_encode(print_r($e->getTrace(), 1)));
        } finally {

            if ($result) {

                $_SESSION['loggedUser'] = $username;
            } else {

                header ( 'Content-Type: application/json' );
                echo json_encode('No user found.');




And finally this is my .htaccess file:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

The problem is that the instruction “$app->redirect(’/dashboard’);” doesn’t work…The browser still remain in login page but in Network inspector i see that the dashboard page is rendered and the route called! I’m getting really mad :slight_smile:

I have also tried many methods with the “$ response” but I did not succeed.

please help me :slight_smile:


I have no experience with Slim Framework v2, but the documentation states:

Please be aware that the following application instance method helpers halt(), pass(), redirect() and stop() are implemented using Exceptions. Each will throw a \Slim\Exception\Stop or \Slim\Exception\Pass exception.

And also

Where possible in your own application you should use typed Exceptions so your catch blocks are more targeted rather than swallowing all Exceptions.

Maybe a try/catch block is interfering with the exception thrown by $app->redirect?