前端之家收集整理的这篇文章主要介绍了
CakePHP重定向,状态码为404,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
对于Cake
PHP错误,我知道存在CakeError和AppError
解决方案.
但我需要在控制器内进行
重定向.
在AppController中存在:
- function afterFilter() {
- if ($this->response->statusCode() == '404')
- {
- $this->redirect(array(
- 'controller' => 'mycontroller','action' => 'error',404),404
- );
- }
- }
但这不会创建404状态代码.它创建了一个302代码.
我把代码更改为:
- $this->redirect('/mycontroller/error/404',404);
但结果是一样的.
我添加了这个,它不起作用也弃用:
- $this->header('http/1.0 404 not found');
如何在控制器重定向中发送404代码?