【发布时间】:2017-04-25 13:09:00
【问题描述】:
我想根据我网站中表单中的信息重定向到一个页面(error.php,或者可能是 404/406.php,无论错误是什么)。我设法记录了这样的错误:
if ($date > $curdate) {
return $response
->withStatus(406)
->withHeader('Content-Type', 'text/html')
->write('You can\'t select dates in the future!');
}
我该怎么做才能将您发送到特别是该错误的页面,而不是在网络选项卡中记录/请求它?
编辑以获得进一步解释:现在我明白了:
Request URL:http://raspberrypi/chartAPI/api/{id}/{date1}/{date2}
Request Method:POST
Status Code:406 Not Acceptable
Remote Address:192.168.0.80:80
Referrer Policy:no-referrer-when-downgrade
这几乎可以按预期工作。我想要做的是将我发送到“http://raspberrypi/chartAPI/error/406”(例如),并将内容显示在一个名为 406.php(或 error406.php 或任何你想调用的文件)的文件中。
Edit2:我现在设法用这个来做点什么:
return $response->withRedirect("error.php");
但我明白了:
Request URL:http://raspberrypi/chartAPI/api/{id}/{date1}/error.php
Request Method:GET
Status Code:405 Method Not Allowed
slim 会抛出这个错误:
Method not allowed. Must be one of: POST
为什么要删除 {date2}?为什么它要求使用 POST 方法?
【问题讨论】:
-
@MikaTuupola 我编辑了我的问题,因为您放置的链接没有帮助。不过还是谢谢!