代码之家  ›  专栏  ›  技术社区  ›  Andrew

Zend框架:如何故意抛出404错误?

  •  26
  • Andrew  · 技术社区  · 14 年前

    我想故意在Zend框架应用程序中的一个控制器内导致404错误。我该怎么做?

    2 回复  |  直到 14 年前
        1
  •  52
  •   Wouter Dorgelo voy    14 年前

    重定向到404将是:

    throw new Zend_Controller_Action_Exception('Your message here', 404);
    

    或无一例外地:

    $this->_response->clearBody();
    $this->_response->clearHeaders();
    $this->_response->setHttpResponseCode(404);
    
        2
  •  1
  •   Juan    14 年前

    您始终可以手动设置响应代码,而不引发任何异常。

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