From aea27d3d7c45eea042ecf7a7ca3dcc32caac30c6 Mon Sep 17 00:00:00 2001 From: Max Mamis Date: Thu, 31 Oct 2013 14:26:28 -0400 Subject: [PATCH] Controller properly maps rest routes like "post()" to the base controller name --- Controller.php | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/Controller.php b/Controller.php index eb62e1e..7fb77f7 100644 --- a/Controller.php +++ b/Controller.php @@ -183,19 +183,24 @@ public function loadRoutes($slim) { $action = strtolower(substr($methodName, 6)); $httpMethod = \Slim\Http\Request::METHOD_DELETE; } - + if (!empty($action)) { - $slim->map("/{$this->base}/{$action}", - array($this, 'preMiddleware'), - array($this, '_runControllerMiddlewares'), - array($this, 'preCallable'), - array($this, $methodName))->via($httpMethod); - $slim->map("/{$this->base}/{$action}(/:param+)", - array($this, 'preMiddleware'), - array($this, '_runControllerMiddlewares'), - array($this, 'preCallable'), - array($this, $methodName))->via($httpMethod); + $action = "/{$action}"; + } + else { + $action = ""; } + + $slim->map("/{$this->base}{$action}", + array($this, 'preMiddleware'), + array($this, '_runControllerMiddlewares'), + array($this, 'preCallable'), + array($this, $methodName))->via($httpMethod); + $slim->map("/{$this->base}{$action}(/:param+)", + array($this, 'preMiddleware'), + array($this, '_runControllerMiddlewares'), + array($this, 'preCallable'), + array($this, $methodName))->via($httpMethod); } }