Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well you are not using bunch of PHP files to get this done... so I think you are on the right track =). The implementation in the article is okay, but very old... was written > 4 years ago. I would suggest looking into <a href="http://framework.zend.com/manual/1.12/en/zend.soap.html" rel="nofollow">Zend_Soap_Server</a>, <a href="http://framework.zend.com/manual/1.12/en/zend.json.server.html" rel="nofollow">Zend_Json_Server</a> or <a href="http://framework.zend.com/manual/1.12/en/zend.rest.server.html" rel="nofollow">Zend_Rest_Server</a>. Soap solution is a bit heavy for the mobile in my opinion.</p> <p>Just decide on the implementation and do little planning!</p> <hr> <p>I wrote a web application and later had to add services layer in order to add mobile app interface to the application. Unfortunately this was not part of initial requirements so had to redo many things. </p> <p>My advice is as follows (if you webapp and api are in a same project):</p> <ol> <li>code all your application logic in library or in controller helpers. So same code can be reused in the main web application and in API layer</li> <li>code your webapp logic in default module</li> <li>code your api layer in a dedicated module called 'api'</li> <li>phpdoc must be perfect in order for zend to autogenerate the SMD</li> </ol> <p>For the API use standard JSON-RPC 2.0 protocol, there are clients for both Android / iPhone that utilize this and provide auto-discovery (SMD like WSDL but for json). All request sent via GET result in SMD being displayed all others result in handling of the request.</p> <p>Utilize <a href="http://framework.zend.com/manual/1.12/en/zend.json.server.html" rel="nofollow">Zend_Json_Server</a> for your API layer. Here is an functional example :</p> <pre><code>&lt;?php // API Controller Example class ApiController extends Zend_Controller_Action { public function init() { parent::init(); $this-&gt;getHelper('ViewRenderer')-&gt;setNoRender(); } public function helloWorldAction() { $this-&gt;_handleRequest('App_Api_HelloWorld'); } protected function _handleRequest($handlerClassName) { // $this-&gt;getHelper('ViewRenderer')-&gt;setNoRender(); // $server = new Zend_Json_Server(); $server-&gt;setClass($handlerClassName); if ($_SERVER['REQUEST_METHOD'] == 'GET') { $cfg = Zend_Registry::get('config'); $req = $this-&gt;getRequest(); $reqUrl = $cfg-&gt;paths-&gt;basehref . $req-&gt;getControllerName() . '/' . $req-&gt;getActionName(); $server-&gt;setTarget($reqUrl) -&gt;setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2); $smd = $server-&gt;getServiceMap(); header('Content-Type: application/json'); echo $smd; } else { // handle request $server-&gt;handle(); } } } // HANDLER Class Example class App_Api_HelloWorld extends App_Api_ApiHandlerAbstract { /** * says "hello world" * * @return string */ public function hello() { return 'hello world'; } /** * says "hello $name" * * @param string $name * @return string */ public function hello2($name) { return "hello $name"; } /** * * @return string * @throws Exception */ public function hello3() { throw new Zend_Json_Server_Exception('not allowed'); return ''; } } </code></pre> <p>Here is sample Request (I added some bootstrap magic to pickup session by id)</p> <pre><code>https://domain.com/api/hello-world { "session_id": "4ggskr4fhe3lagf76b5tgaiu57", "method": "hello2", "params": { "name" : "Alex" }, "id": 123 } </code></pre> <p>Review <a href="http://www.jsonrpc.org/specification" rel="nofollow">JSON RPC 2.0 Documentation</a>.</p> <p>I found <a href="https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo?hl=en-US" rel="nofollow">Advanced REST Client</a> for Google Chrome to be BEST extension for developing and testing JSON web services.</p> <p>For additional security you can restrict ALL the request via <a href="http://php.net/manual/en/features.http-auth.php" rel="nofollow">HTTP Auth</a> by adding few lines of code to the abstract controller or even create security <a href="http://framework.zend.com/manual/1.12/en/zend.controller.plugins.html" rel="nofollow">controller plugin</a>.</p> <p>Good Luck.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload