这是一个令人感兴趣的问题。 现在我并不完全相信,这样我就能够研究这个问题,看看我所看到的情况。 如今,有些工作环绕太了贫民窟。 一种办法是建立一个抽象的控制器,从中将你的控制器扩展到其余模块。
abstract class RestAbstractController extends Zend_Rest_Controller
{
final public function __call($methodName, $args)
{
throw new MyRestException("Method {$methodName} doesn t exist", 500);
}
}
// the extends part here is optional
class MyRestException extends Zend_Rest_Exception
{
public function fault($exception = null, $code = null)
{
echo $exception->getMessage() . . __CLASS__;
exit;
}
}
class RestController extends RestAbstractController
{
// method list
}
另外,我发现这一有趣的文章:
Edit:
在座boot中,你需要补充:
$this->_front->throwExceptions(true);
$ex = new MyRestException();
set_exception_handler(array($ex, fault ));
The first line there should effectively turn off Zend s exception handling, the only thing missing is a control structure to determine if the current request is for your REST service or not. NOTE The reason this had to go in the Bootstrap.php file was that your call to set_exception_handler() in the init() function was never reached because Zend Framework threw the exception first. Placing that in the bootstrap file will counter that.