Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have Subclassed multiple classes to achieve this and created static routes for admin/api</p> <pre><code>Application Bootstrap protected function _initRoute() { $front = Zend_Controller_Front::getInstance(); $router = $front-&gt;getRouter(); $dispatcher = $front-&gt;getDispatcher(); $request = $front-&gt;getRequest(); $defaultRoute = new Pwb_Controller_Router_Route_Module(array(), $dispatcher, $request); //Replace default route in our router with our own route $router-&gt;addRoute('default', $defaultRoute); $adminRoute = new Pwb_Controller_Router_Route( ':admin', array(), array( 'admin' =&gt; 'admin' ) ); $adminDefault = $adminRoute-&gt;chain($defaultRoute); $router-&gt;addRoute('admin', $adminRoute); $router-&gt;addRoute('admin', $adminDefault); $apiRoute = new Pwb_Controller_Router_Route( ':api', array(), array( 'api' =&gt; 'api' ) ); $apiDefault = $apiRoute-&gt;chain($defaultRoute); $router-&gt;addRoute('api', $apiDefault); $router-&gt;addRoute('api', $apiRoute); } Rest Route class Pwb_Controller_Router_Rest extends Zend_Rest_Route { public function match($request, $partial = false) { if (!$request instanceof Zend_Controller_Request_Http) { $request = $this-&gt;_front-&gt;getRequest(); } $this-&gt;_request = $request; $this-&gt;_setRequestKeys(); $path = $request-&gt;getPathInfo(); $params = $request-&gt;getParams(); $values = array(); $path = trim($path, self::URI_DELIMITER); if ($path != '') { $path = explode(self::URI_DELIMITER, $path); //Determine Environment if($path[0] != 'api') { return false; } else { array_shift($path); } // Determine Module $moduleName = $this-&gt;_defaults[$this-&gt;_moduleKey]; $dispatcher = $this-&gt;_front-&gt;getDispatcher(); if ($dispatcher &amp;&amp; $dispatcher-&gt;isValidModule($path[0])) { $moduleName = $path[0]; if ($this-&gt;_checkRestfulModule($moduleName)) { $values[$this-&gt;_moduleKey] = array_shift($path); $this-&gt;_moduleValid = true; } } // Determine Controller $controllerName = $this-&gt;_defaults[$this-&gt;_controllerKey]; if (count($path) &amp;&amp; !empty($path[0])) { if ($this-&gt;_checkRestfulController($moduleName, 'api_' . $path[0])) { $controllerName = 'api_' . $path[0]; $values[$this-&gt;_controllerKey] = 'api_' . array_shift($path); $values[$this-&gt;_actionKey] = 'get'; } else { // If Controller in URI is not found to be a RESTful // Controller, return false to fall back to other routes return false; } } elseif ($this-&gt;_checkRestfulController($moduleName, $controllerName)) { $values[$this-&gt;_controllerKey] = $controllerName; $values[$this-&gt;_actionKey] = 'get'; } else { return false; } //Store path count for method mapping $pathElementCount = count($path); // Check for "special get" URI's $specialGetTarget = false; if ($pathElementCount &amp;&amp; array_search($path[0], array('index', 'new')) &gt; -1) { $specialGetTarget = array_shift($path); } elseif ($pathElementCount &amp;&amp; $path[$pathElementCount-1] == 'edit') { $specialGetTarget = 'edit'; $params['id'] = urldecode($path[$pathElementCount-2]); } elseif ($pathElementCount == 1) { $params['id'] = urldecode(array_shift($path)); } elseif ($pathElementCount == 0 &amp;&amp; !isset($params['id'])) { $specialGetTarget = 'index'; } // Digest URI params if ($numSegs = count($path)) { for ($i = 0; $i &lt; $numSegs; $i = $i + 2) { $key = urldecode($path[$i]); $val = isset($path[$i + 1]) ? $path[$i + 1] : null; $params[$key] = urldecode($val); } } // Determine Action $requestMethod = strtolower($request-&gt;getMethod()); if ($requestMethod != 'get') { if ($request-&gt;getParam('_method')) { $values[$this-&gt;_actionKey] = strtolower($request-&gt;getParam('_method')); } elseif ( $request-&gt;getHeader('X-HTTP-Method-Override') ) { $values[$this-&gt;_actionKey] = strtolower($request-&gt;getHeader('X-HTTP-Method-Override')); } else { $values[$this-&gt;_actionKey] = $requestMethod; } // Map PUT and POST to actual create/update actions // based on parameter count (posting to resource or collection) switch( $values[$this-&gt;_actionKey] ){ case 'post': if ($pathElementCount &gt; 0) { $values[$this-&gt;_actionKey] = 'put'; } else { $values[$this-&gt;_actionKey] = 'post'; } break; case 'put': $values[$this-&gt;_actionKey] = 'put'; break; } } elseif ($specialGetTarget) { $values[$this-&gt;_actionKey] = $specialGetTarget; } } $this-&gt;_values = $values + $params; $result = $this-&gt;_values + $this-&gt;_defaults; if ($partial &amp;&amp; $result) $this-&gt;setMatchedPath($request-&gt;getPathInfo()); return $result; } } Module Bootstrap; class Acl_Bootstrap extends Zend_Application_Module_Bootstrap { protected function _initRestRoute() { $this-&gt;bootstrap('frontController'); $frontController = Zend_Controller_Front::getInstance(); $restRoute = new Pwb_Controller_Router_Rest( $frontController, array(), array( 'acl' =&gt; array( 'api_role' )) ); $frontController-&gt;getRouter()-&gt;addRoute('restAcl', $restRoute); } } class Pwb_Controller_Router_Route_Module extends Zend_Controller_Router_Route_Module { public function match($path, $partial = false) { $return = parent::match($path, $partial); $front = Zend_Controller_Front::getInstance(); $request = $front-&gt;getRequest(); $is_admin_env = $request-&gt;getParam('is_admin_env'); if($is_admin_env) { $return['controller'] = $is_admin_env . '_' . $return['controller']; } return $return; } } class Pwb_Controller_Router_Route extends Zend_Controller_Router_Route { public function match($path, $partial = false) { $return = parent::match($path, $partial); if(isset($return['admin'])) { $front = Zend_Controller_Front::getInstance(); $request = $front-&gt;getRequest(); $request-&gt;setParam('is_admin_env', $return['admin']); $front-&gt;setRequest($request); } return $return; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    1. This table or related slice is empty.
    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