Zend Framework: How to intentionally throw a 404 error?

后端 未结 2 1733
耶瑟儿~
耶瑟儿~ 2021-02-01 16:52

I would like to intentionally cause a 404 error within one of the controllers in my Zend Framework application. How can I do this?

2条回答
  •  太阳男子
    2021-02-01 17:10

    You can always set the response code manually, without throwing any exceptions.

    $this->_response->clearBody();
    $this->_response->clearHeaders();
    $this->_response->setHttpResponseCode(404);
    

提交回复
热议问题