(on Monday, 15 December 2008, 01:39 PM +0100):
> I'm trying to build a JsonRest server using php Zend Framework and I'm having a
> little problem getting the request parameters on POSTs. I'm using this :
> private function _POST($params)
> {
> $request = $this->getRequest();
> $params = $request->getParams();
> if(!isset($params['testID']))
> return $this->sendJson("Error, testID is not set");
> ...
> }
>
> Now the dojo client is sending a testID parameter with data in it (see down)
> but I don't seem to be able to get the parameters from inside the _POST
> function.
> Isn't the getParams() function supposed to send back all the parameters of a
> request ?
> Why doesn't this works for a xhr request ?
Dojo is sending a *json* payload -- which means you need to grab the
parameters from the raw POST and decode them:
$payload = $request->getRawPost();
$params = Zend_Json::decode($payload);
> dojo client :
>
> var a = tstore.newItem();
> tstore.setValue(a, "testID", "Test");
>
> tstore.save({
> onComplete: function(){ console.debug("save ok");},
> onError: function(err){
> console.debug("error:", err);
> }
> });
--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/
没有评论:
发表评论