It’s very unclear, both in the Zend documentation and the Dojo one, how it is possible to order a JsonRest server (the Zend one while we’re at it!) to reply to JsonRest client (dojo…). I’ve tryied to make this happen for 2 days now… Here’s the client side :

  1. <b style=”color:black;background-color:#ffff66″>dojo</b>.addOnLoad(function(){
  2. store = new dojox.data.JsonRestStore({target:”/test/m”});
  3. var newItem = store.newItem(
  4. {
  5. post_id: 123
  6. });
  7. store.save();
  8. (…)

Then, on the server side : x First modify the router :

  1. $route = new Zend_Controller_Router_Route(‘test/m/:id/*’, array(‘controller’=>’test’, ‘action’=>’m’));
  2. $front->getRouter()->addRoute(‘test’, $route);

x Then add a a function in a custom class :

  1. /*
  2. * returns hello world
  3. * @return string
  4. *
  5. */
  6. public static function addmyitem($item){
  7. // custom code
  8. return “Item added”;
  9. }

=> But, how am I supposed to map this function to the action controller in order to reply to the Rest POST request dojo is executing ??? That’s not getting me anywhere…

  1. // Disable auto-rendering and layouts
  2. $this->_helper->viewRenderer->setNoRender(true);
  3. $this->_helper->layout->disableLayout(true);
  4. $id = $this->getRequest()->getParam(‘id’);
  5. $server = new Zend_Json_Server();
  6. $server->setClass(‘RpcTest’);
  7. if(‘GET’ == $_SERVER[‘REQUEST_METHOD’]){
  8. $server->setTarget(‘/test/m’)
  9. ->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2);
  10. $smd->setDojoCompatible(true);
  11. header(‘Content-Type: application/<b style=”color:black;background-color:#99ff99″>json</b>’);
  12. echo $smd;
  13. return;
  14. }
  15. $server->handle();

Finally I’m questionning the use of the Zend Json server : would’nt it be simpler to get rid of the server and directly reply using :

  1. if(‘GET’ == $_SERVER[‘REQUEST_METHOD’]){
  2. $data = get_item_data_by_id($this->getRequest()->getParam(‘id’));
  3. sendToJson($data);
  4. }

Now : how are we supposed to make this work ?

Advertisements