Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3932044
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:24:49+00:00 2026-05-19T23:24:49+00:00

I am trying to serve up my user repository via zend_json_server. The problem is

  • 0

I am trying to serve up my user repository via zend_json_server. The problem is the service is returning empty objects. What have i missed?
server side:

$repo = App_User_Repository::getInstance();

  $server = new Zend_Json_Server();
  $server->setClass($repo);

  if ('GET' == $_SERVER['REQUEST_METHOD']) {
      $server->setTarget('/service/json-rpc.php')
             ->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2);
      $smd = $server->getServiceMap();

      // Set Dojo compatibility:
      $smd->setDojoCompatible(true);
      header('Content-Type: application/json');
      echo $smd;
      return;
  }

  $server->handle();

client side:

    var object = new dojo.rpc.JsonService('/service/json-rpc.php');
    var deferred = object.getById(1);
    deferred.addBoth(function(result) {console.log(result)});

Firebug console output:

 Object {}

This should be a User object

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T23:24:49+00:00Added an answer on May 19, 2026 at 11:24 pm

    When doing the actual RPC with the “getById()” method, an dojo.deferred object is returned. At this point, a asynchronous request is running. By using the deferred object, you can define callbacks and error handlers in advance whilst waiting for the response to be returned.

    Check if the actual response object isn’t empty as well. Remember, you still have to use the return keyword in your attached classes to return results back to Zend_Json_Server. Zend_Json_Server will then serialize and send back the returned value automatically. A response from Zend_Json_Server is always a serialized object in JSON, containing an id (which increments automatically with each request), an string indicating what jsonrpc version is being used (ie. 2.0) and of course a result containing the returned data from the attached class.

    The setClass() method should not be a object instance, but a string containing the className of the class you want to attach. Zend_Json_Server handles the creation of the object instance by itself, as well as generating the SMD (Service Method/Mapper Description). Remember to document each public method with docblocks, as Zend_Json_Server uses those docblocks to determine the SMD.

    Furthermore, it is much more handy to use a fluent-like interface with the then() method like so:

    var myService = new dojo.rpc.JsonService('/service/json-rpc.php?');
    var deferredObj = myService.doThis('myArgument');
    deferredObj.then(callback, errorHandler).then(afterCallback).then(cleanUp);
    

    In above example, the variables callback, errorHandler, afterCallback and cleanUp, are actually references to functions. The first then() method you call, automatically passes the rpc result to the callback function. If you throw an exception from within the attached rpc class, the errorHandler method (second optional argument of the first then() method call) will be called instead.

    More information: http://www.sitepen.com/blog/2010/05/03/robust-promises-with-dojo-deferred-1-5/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to get my server to serve my rails apps. I have a test
I'm trying to connect to a server that the user inputs. When the server
I have been trying to set up an svn repository on an ubuntu 11.04
I have cloned a remote repository and made a few commits. I am trying
I'm trying to insert a user in my database via LINK to SQL and
Here's the situation: We have a git repository, managed by gitosis. One user user
I have a quick question about how to serve data from a repository in
I'm trying to find a way to serve the correct video format (I have
I am trying to serve a svg map using: <object data=map.svg type=image/svg+xml width=400 height=300>
I'm trying to serve a property list of search results to my iPhone app.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.