Skip to content
Snippets Groups Projects
Commit eacdb5ef authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

fix modularized routes

parent 696a5dcd
Branches
1 merge request!2Pluggable restful
......@@ -46,27 +46,28 @@ class Restful_Bootstrap {
* @param Zend_Controller_Front $controller
* @param strings $prefix
*/
public static function asPlugin($controller, $prefix, $viewRenderer) {
static::_addRoutes($controller->getRouter(), $prefix);
public static function asPlugin($controller, $named, $viewRenderer) {
static::_addRoutes($controller->getRouter(), $named);
if ($viewRenderer)
$viewRenderer->view->addHelperPath('Restful/View/Helper', 'Restful_View_Helper');
}
protected static function _addRoutes($router, $prefix) {
$prefixed = function($path) use ($prefix) { return $prefix.$path; } ;
protected static function _addRoutes($router, $module) {
$prefixed = function($path) use ($module) { return ($module) ? $module.'/'.$path : $path; };
$moduled = function($params) use ($module) { return ($module) ? array_merge($params, ['module' => $module]) : $params ; };
$router
->addRoute('restindex',
new Zend_Controller_Router_Route($prefixed(':model/*'), ['page' => 1]))
new Zend_Controller_Router_Route($prefixed(':model/*'), $moduled(['page' => 1])))
->addRoute('restshow',
new Zend_Controller_Router_Route($prefixed(':model/:id'), ['action' => 'show']))
new Zend_Controller_Router_Route($prefixed(':model/:id'), $moduled(['action' => 'show'])))
->addRoute('restnew',
new Zend_Controller_Router_Route($prefixed(':model/new'), ['action' => 'new']))
new Zend_Controller_Router_Route($prefixed(':model/new'), $moduled(['action' => 'new'])))
->addRoute('restedit',
new Zend_Controller_Router_Route($prefixed(':model/:id/edit'), ['action' => 'edit']))
new Zend_Controller_Router_Route($prefixed(':model/:id/edit'), $moduled(['action' => 'edit'])))
->addRoute('restcatalog',
new Zend_Controller_Router_Route_Static($prefixed('catalog'), ['action' => 'catalog']))
new Zend_Controller_Router_Route_Static($prefixed('catalog'), $moduled(['action' => 'catalog'])))
;
}
......
......@@ -50,6 +50,10 @@ class Restful_Controller extends Zend_Controller_Action {
$params = $this->_request->getParams();
unset($params['model']);
unset($params['module']);
unset($params['controller']);
unset($params['action']);
unset($params['current_module']);
$page = $this->_getParam('page', 1);
unset($params['page']);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment