Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to set up Hierarchical Zend Rest Routes?
    text
    copied!<p>With the Zend Framework, I am trying to build routes for a REST api on resources organized in the following pattern:</p> <ul> <li><a href="http://example.org/users/" rel="noreferrer">http://example.org/users/</a></li> <li><a href="http://example.org/users/234" rel="noreferrer">http://example.org/users/234</a></li> <li><a href="http://example.org/users/234/items" rel="noreferrer">http://example.org/users/234/items</a></li> <li><a href="http://example.org/users/234/items/34" rel="noreferrer">http://example.org/users/234/items/34</a></li> </ul> <p>How do I set up this with Zend_Rest_Route?</p> <p>Here is how I have setup the route for the users resource (users/:id) in my bootstrap.php file:</p> <pre><code> $this-&gt;bootstrap('frontController'); $frontController = Zend_Controller_Front::getInstance(); $restRoute = new Zend_Rest_Route($frontController); $frontController-&gt;getRouter()-&gt;addRoute('default', $restRoute); </code></pre> <p>[As far as I understand, this is a catch all route so users/324/items/34 would results in parameters set as id=324 and items=34 and everything would be mapped to the Users (front module) Model. From there I guess I could just test for the items parameter and retrieve the item #34 for user #324 on a get request.]&lt;=== I just checked it and it doesn't seems to work like that: </p> <p>Acessing /users/234/items/43 and</p> <pre><code>var_dump($this-&gt;_getAllParams()); </code></pre> <p>in the get action of the rest controller results in the following output:</p> <pre><code>array(4) { ["controller"]=&gt; string(5) "users" ["action"]=&gt; string(3) "get" [2]=&gt; string(5) "items" ["module"]=&gt; string(7) "default"] } </code></pre> <p>Somehow both ids got lost...</p> <p>Anyone?</p>
 

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