title: Zend Rest Route: goto the right method (get/put/post/delete)
body: <p>I am retiring a custom PHP project that was used as an API.</p>
  
  <p>I need to support such URLS such as </p>
  
  <p>/post/{id}/copy.json (copy post with {id}
  /post (all posts)
  /post/{id} (return one post)</p>
  
  <p>So far its going okay, however routing I'm finding difficult. I would like Zend to detect what type of request it is and then use the correct method. I am leaning towards putting that in My_Controller_Rest predispatch, passing a variable back to the controller and then in indexAction doing $this->getAction()</p>
  
  <p>Thoughts? I kind of assumed using Zend_Rest_Controller it would fire off the right method, and unless I'm doing it wrong, its not.</p>
  
  <p>All my controllers extend an abstract class,</p>
  
  <p>Controller:</p>
  
  <pre><code>&lt;?php
  
  class Post_IndexController extends My_Controller_Rest
  {
  
  
      public function init()
      {
      }
  
  
      public function indexAction()
      {
  
      }
  
  
      public function getAction()
      {
      }
  
  
      public function postAction()
      {
      }
  
  
      public function putAction()
      {
      }
  
  
      public function deleteAction()
      {
      }
  
  
  }
  </code></pre>
  
  <p>My Controller Rest</p>
  
  <pre><code>&lt;?php
  
  
  abstract class My_Controller_Rest extends Zend_Rest_Controller {
  
  
      public function preDispatch() {
  
          $this-&gt;_helper-&gt;viewRenderer-&gt;setNoRender(true);
          $request        = Zend_Controller_Front::getInstance()-&gt;getRequest();
          $this-&gt;output   = null;
  
          //get registry versions
          $config         = Zend_Registry::get('config');
          $cache          = Zend_Registry::get('cache');
          $log            = Zend_Registry::get('log');
          $loggers        = Zend_Registry::get('loggers');
  
          //internal to the view
          $this-&gt;_config      = $config;
          $this-&gt;_cache       = $cache;
          $this-&gt;_log         = $log;
  
          $this-&gt;data = array();
          $this-&gt;data['module']   = $request-&gt;getModuleName();
          $this-&gt;data['controller'] = $request-&gt;getControllerName();
          $this-&gt;data['action']   = $request-&gt;getActionName();
          $this-&gt;data['loggers']  = $loggers;
      }
  
  
      public function postDispatch() {
          header('Content-type: text/json');
          header('Content-type: application/json');
  
          echo json_encode(array('output' =&gt; $this-&gt;output, 'data' =&gt; $this-&gt;data));
          exit;
      }
  
  
  }
  </code></pre>
  
  <p>UPDATE:</p>
  
  <p>I resolved this by using the Resauce: <a href="https://github.com/mikekelly/Resauce" rel="nofollow">https://github.com/mikekelly/Resauce</a></p>
  
  <p>You can find my improvements by looking here: <a href="https://github.com/mikekelly/Resauce/issues/1" rel="nofollow">https://github.com/mikekelly/Resauce/issues/1</a></p>