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 7163303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:52:50+00:00 2026-05-28T13:52:50+00:00

I’m looking to create a web site and will be creating a mobile app

  • 0

I’m looking to create a web site and will be creating a mobile app at a later date.

I want to be able to offer the same level of data (i.e. a listing of books) to both the web site and the app. I’d like to use an API for this but am struggling to find any examples or decent articles online.

So I suppose my question is, if I were to create a JSON ‘endpoint’ accessible by a mobile app over HTTP (e.g. http://www.mysite.com/api/v1.0/json) how do access the same functionality internally from my Zend Application?

(obviously I don’t want to duplicate the database interaction ‘model’ steps)

  • 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-28T13:52:51+00:00Added an answer on May 28, 2026 at 1:52 pm

    Since Zend is really not RESTful, unfortunately, your best bet is JSON-Rpc.

    You can do it in a controller, or you can just make an ajax.php in addition to your index.php to reduce overhead like this guy did here

    Basically, all you need to do is this:

    $server = new Zend_Json_Server();
    $server->setClass('My_Class_With_Public_Methods');
    // I've found that a lot of clients only support 2.0
    $server->getRequest()->setVersion("2.0");
    if ('GET' == $_SERVER['REQUEST_METHOD']) {
        // Indicate the URL endpoint, and the JSON-RPC version used:
        $server->setTarget('/ajax.php')
               ->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2);
    
        // Grab the SMD
        $smd = $server->getServiceMap();
    
        // Return the SMD to the client
        header('Content-Type: application/json');
        echo $smd;
        return;
    }
    
    $server->handle();
    

    then somewhere in your layout:

    $server = new Zend_Json_Server();
    $server->setClass('My_Class_With_Public_Methods');
    $smd = $server->getServiceMap();
    ?>
    <script>
    $(document).ready(function() {
        rpc = jQuery.Zend.jsonrpc({
            url : <?=json_encode($this->baseUrl('/ajax'))?>
            , smd : <?=$smd?>
            , async : true
        });
    });
    </script>
    

    for the sake of example, here’s that class:

    class My_Class_With_Public_Methods {
        /**
          * Be sure to properly phpdoc your methods,
          * the rpc clients like it when you do
          * 
          * @param float $param1
          * @param float $param2
          * @return float
          */
        public function someMethodInThatClass ($param1, $param2) {
            return $param1 + $param2;
        }
    }
    

    then you can simply call methods like so in javascript:

    rpc.someMethodInThatClass(first_param, second_param, {
        // if async = true when you setup rpc,
        // then the last param is an object w/ callbacks
        'success' : function(data) {
    
        }
        'error' : function(data) {
    
        }
    });
    

    There aren’t a lot of well known JSON-rpc libraries for Android / iPhone – but I have found that this works with Zend_Json_Server for Android:

    http://software.dzhuvinov.com/json-rpc-2.0-base.html

    and this works for iPhone:

    http://www.dizzey.com/development/ios/calling-json-rpc-webservice-in-ios/

    From here, obviously, you can use My_Class_With_Public_Methods in the same way that javascript / your mobile app does.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.