【问题标题】:Getting post variables in zend rest controller在zend rest控制器中获取post变量
【发布时间】:2012-04-02 10:39:15
【问题描述】:

我想在init() 函数中将POST 数据发送到页面控制器,但我得到的是一个空数组。

但是,获取getRawBody 会显示数据。

这是我使用的命令:

curl http://localhost/api/page/7 -X PUT -d "test=true"

输出是:

数组 ( ) 测试=真

class Api_PageController extends Zend_Rest_Controller
{
    public function init()
    {
        $this->_helper->viewRenderer->setNoRender();
        $this->_helper->layout->disableLayout();
        print_r($this->getRequest()->getPost());
        print_r($this->getRequest()->getRawBody());    
    }
}

【问题讨论】:

    标签: zend-framework zend-rest


    【解决方案1】:

    您想要的是 PutHandler 插件。这将使 POST 和 PUT 使用相同的 getParams();

    把它放在你的 application.ini

    resources.frontController.plugins.putHandler = Zend_Controller_Plugin_PutHandler
    

    那么数据应该会在你调用的时候出现

    $this->getRequest->getParams();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-24
      • 2017-09-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多