Slim Framework在重定向上显示空白页面(Slim Framework shows blank page on redirect)

编程入门 行业动态 更新时间:2024-10-18 01:42:12
Slim Framework在重定向上显示空白页面(Slim Framework shows blank page on redirect)

我正在尝试使用Slim Framework的重定向,但它根本不起作用。 这是一个例子:

// 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'))); });

当我在上一页提交表单时,它会发布到/ n /:id,但随后只显示一个空白页面。 ifelse语句中的主页重定向也是如此。 如果我打开Chrome开发人员工具,我可以看到请求的状态是200,方法是POST。 将error_log添加到请求处理程序会向我显示请求已发出,但重定向不执行任何操作。 我已启用所有错误报告,但未显示任何内容。

几个小时前它正在工作,所以我不知道它有什么问题。 有什么想法吗?

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?

最满意答案

我意识到它是什么,现在讨厌自己。 我在重定向之前包含了一个带有require的库,并且该库在<?php之前有一个空格,所以发送了一个空行。 这意味着标题已经设置,因此重定向不起作用。

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.

更多推荐

本文发布于:2023-07-16 12:55:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1128661.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   空白   页面   Framework   Slim

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!