From 565f3dee47f8d6bb35b485984c920d9a13d9c215 Mon Sep 17 00:00:00 2001 From: Dinesh Ilindra Date: Sun, 26 Feb 2012 13:00:51 +0530 Subject: [PATCH] Some controllers may have parameters in "Routing Prefix" too. Supporting those controllers as well while generating URLs using "urlTo()". --- .../framework/controllers/Controller.class.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/recess/recess/framework/controllers/Controller.class.php b/recess/recess/framework/controllers/Controller.class.php index ae0d9f2..753bfca 100644 --- a/recess/recess/framework/controllers/Controller.class.php +++ b/recess/recess/framework/controllers/Controller.class.php @@ -117,6 +117,19 @@ public function urlTo($methodName) { $url = substr($url, 1); } + // Checks if the routes prefix has some parameters and + // replaces them with actual values from request meta data. + $prefixParts = explode('/',$descriptor->routesPrefix); + $prefixParams = array(); + $prefixParamValues = array(); + foreach($prefixParts as $part) { + if(strpos($part, '$') !== false) { + $prefixParams[] = $part; + $prefixParamValues[] = $this->request->meta->controllerMethodArguments[substr($part,1)]; + } + } + $url = str_replace($prefixParams, $prefixParamValues, $url); + if(!empty($args)) { $reflectedMethod = new ReflectionMethod($this, $methodName); $parameters = $reflectedMethod->getParameters();