Slim V2重定向不会重定向

时间:2017-03-31 12:50:22

标签: php apache .htaccess slim

我有Slim V2路由指令的问题。问题是登录后我无法重定向到我的仪表板页面!

这是我的index.php代码:

<?

    require_once 'vendor/autoload.php';

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


    require("config/database.php");
    require_once("vendor/dabble/dabble/src/Dabble/Database.php");
    require_once("vendor/dabble/dabble/src/Dabble/Result.php");




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

    session_start();

    date_default_timezone_set("Europe/Rome");

    require 'app/GeCo.php';

    $app->run();

?>

这是GeCo.php标记:

<?php

    require_once('classes/Login.php');
    use login\Login;


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

        $app->redirect('/dashboard');

    });

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

        $page = 'login.php';
        $app->render($page);

    });

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

        $page = 'dashboard.php';
        $app->render($page);

    })->name('dash');;


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

        try {

            $result=[];
            $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;
                $_SESSION['password']=md5($password);
                $app->redirect('/dashboard');
            } else {

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

            }

        }

    });

最后这是我的.htaccess文件:

RewriteEngine On

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

问题是指令$app->redirect('/dashboard');不起作用。浏览器仍然保留在登录页面中,但在网络检查器中,我看到仪表板页面已呈现并且路径被调用!

我也尝试了$ response的许多方法,但我没有成功。

0 个答案:

没有答案