在ASP.NET MVC中,可以通過[HttpPost]或者[HttpGet]标簽使得Action方法隻響應指定的送出方式。
在Zend Framework中沒有這種标簽方式,是以實作方式有點不同。
在ZF中,所有的Controller都有preDispatch方法,該方法在action方法調用前被調用,是以可以在這個方法上做文章。
public function preDispatch(){
if($this->_request->isPost())//如果是post動作
{
//如果請求的action不在提供的清單中,則退出程式。
if (false==in_array($this->getRequest()->getActionName(), array('onlypost'))) {
exit('The action cannot be called by post');
}
}
if($this->_request->isGet())//如果是Get動作
{
//如果請求的action不在提供的清單中,則退出程式。
if (false==in_array($this->getRequest()->getActionName(), array('onlyget'))) {
exit('The action cannot be called by Get');
}
}
}