dongningwen1146 2014-07-30 15:08
浏览 43
已采纳

Slim Framework在重定向上显示空白页面

I'm trying to use Slim Framework's redirect, however it isn't working at all. Here is an example:

// Viewing a note
$app->get('/n/:id(/:password)', function ($id, $password = null) use ($app, $tl, $settings){
    // User has requested a note
    $note = $tl->load($id);
    // Check if note is valid
    if ($note) {
        // No problems, note is valid
        $app->render('note.php', ['note' => $note, 'settings' => $settings, 'password' => $password]);
    } else {
        // Note has been deleted or doesn't exist, render error
        $app->flash('error', '<p>The requested note doesn\'t exist. It may have expired or been deleted.</p>');
        $app->redirect('/');
    }
});

// Get posted password
$app->post('/n/:id', function ($id) use ($app) {
    // Hash password, redirect user back to note
    $app->redirect('/n/' . $id . '/' . SHA1($app->request->post('password')));
});

When I submit the form on the previous page, it posts to /n/:id, but then simply displays a blank page. The same goes for the homepage redirect in the ifelse statement. If I open the Chrome developer tools, I can see that the status of the request is 200, and the method is POST. Adding an error_log to the request handler shows me that the request is made, but the redirect does nothing. I've enabled all error reporting, but nothing is shown.

It was working literally hours ago, so I have no idea what's wrong with it. Any thoughts?

  • 写回答

1条回答 默认 最新

  • dourangdz750379 2014-08-11 16:57
    关注

    I realised what it was, and now hate myself. I was including a library with require before my redirect, and that library had a blank space before <?php, so an empty line was being sent. This meant that the headers were already set so the redirect didn't work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败