【发布时间】:2017-04-26 08:49:08
【问题描述】:
我想根据我网站表单中的信息重定向到一个页面(例如error.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,或 error.php 或其他任何名称)的文件中显示内容。
我设法用这个做点什么:
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 方法?
这个问题是this one的延续,但是由于这个网站如何处理这些“老”问题,我的问题被推倒了,不管我做了多少编辑,它都不再受到关注了。
【问题讨论】:
-
@geggleto 这就是我在问题结束时所说的。