Zend 1.12 Rest PUT方法不允许

时间:2012-10-16 23:38:53

标签: zend-framework zend-rest

自从我迁移到AWS并更新到PHP 5.4和Zend 1.12后,我遇到了PUT& amp; DELETE方法。

一个简单的例子:

/ ** Zend 1.12 ** /

/ ** bootstrap / routes ** /

$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

结果:get ===>好的

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>

===&GT;不行

我不必使用WebDav(或其他)Apache插件来启用PUT / DELETE请求。 PHP Handler处理的是,而不是Apache。 那么为什么,GET没关系,PUT不行?为什么Apache说一些关于index.php而不是/rest/RestController.php?

我看到Zend从1.12开始更新它的Zend_Rest_Controller。现在,我要声明“headAction”函数,但我没有找到关于这一点的文档......

如果您有任何想法......

谢谢,

1 个答案:

答案 0 :(得分:0)

问题可能源于Apache配置。 也许你应该继续添加像

这样的东西
<Directory />
    AllowOverride All
    <Limit GET HEAD POST PUT DELETE OPTIONS>
        Order Allow,Deny
        Allow from all
    </Limit>
</Directory>

到你的apache配置。

查看此answer