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.

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

报告相同问题?

悬赏问题

  • ¥15 怎样才能让鼠标沿着线条的中心线轨迹移动
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?