公告
财富商城
积分规则
提问
发文
2019-04-19 07:09发布
Explosion°爆炸
I want to throw a '404 Page not found' error from my controller. How can I do that?
I use Zend Framework 2 not 1.
Just try with:
$this->getResponse()->setStatusCode(404); return;
in your controller's action method.
In the correct ZF2 setup you should already have your 404 view, then in your controller action just use the following and the 404 is automatically handled for you:
if($notTheCorrectSlugMatchOrWhatEver){ return $this->notFoundAction(); }
class IndexController extends AbstractActionController { public function previewAction () { return $this->notFoundAction (); } }
最多设置5个标签!
Just try with:
in your controller's action method.
In the correct ZF2 setup you should already have your 404 view, then in your controller action just use the following and the 404 is automatically handled for you: