由於我已遷移到AWS並更新到PHP 5.4和Zend 1.12,所以我在使用PUT & DELETE方法時遇到問題。Zend 1.12不允許休息PUT方法
快速爲例:
/** Zend的1.12 **/
/**引導/路線**/
$front = \Zend_Controller_Front::getInstance();
$front->setParam('bootstrap',$this);
//REST API
$router = $front->getRouter();
$restRoute = new Zend_Rest_Route($front, array(), array(
'default' => array('rest'),
));
$router->addRoute('rest', $restRoute);
/** ** restController/
//module : default
class RestController extends \Zend_Rest_Controller
public function init(){
parent::init();
$this->_helper->viewRenderer->setNoRender(true);
$this->_helper->layout->disableLayout();
}
public function headAction(){}
public function indexAction()
{
Throw new AppException(Translator::translate('index not yet implemented...'));
}
public function getAction()
{
die('get');
}
public function putAction(){
die('put');
}
/* TestCase */
curl -X GET http://XXXX/rest/MS4xMjU2LjEyNTguMTI2MS4tbW9kZWxzXGNvcmVcbW9kZWxcZXhlcmNpc2VcZXhlcmNpc2VfcXVlc3Rpb24tMTQy
結果:獲得===> OK
curl -X PUT http://XXXX/rest/MS4xMjU2LjEyNTguMTI2MS4tbW9kZWxzXGNvcmVcbW9kZWxcZXhlcmNpc2VcZXhlcmNpc2VfcXVlc3Rpb24tMTQy
結果:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>405 Method Not Allowed</title>
</head><body>
<h1>Method Not Allowed</h1>
<p>The requested method PUT is not allowed for the URL /index.php.</p>
<hr>
<address>Apache/2.2.16 (Debian) Server at XXXXX Port 80</address>
</body></html>
===>不正常
我不必使用WebDAV(或其他)Apache插件來啓用PUT/DELETE請求。 PHP處理程序處理該問題,而不是Apache。 那麼,爲什麼,GET是好的,而PUT不是?爲什麼Apache說一些關於index.php而不是/rest/RestController.php?
我看到Zend從1.12開始更新它的Zend_Rest_Controller。現在,我已經申報「headAction」的功能,但我沒有在這一點上找到文檔...
如果你有什麼想法?
感謝,
可能重複[如何啓用和使用HTTP PUT和DELETE與Apache2和PHP?](http://stackoverflow.com/questions/2934554/how-to-enable-and-use-http-put-and -delete-with-apache2-and-php) –