OSDN Git Service

Fix in Router::generate()
authorlpotherat <l.potherat@planetb.fr>
Fri, 31 Mar 2017 14:21:05 +0000 (16:21 +0200)
committerGitHub <noreply@github.com>
Fri, 31 Mar 2017 14:21:05 +0000 (16:21 +0200)
Fix in Router::generate(), replace matching key in url while looping through param_key.

otherwise, with route  : /action/:type/:id , $router->generate($namedRoute,['id'=>1,'type'=>'type']) generate /action/1/type.

src/Router.php

index ed3d660..d32656e 100755 (executable)
@@ -177,7 +177,7 @@ class Router
             // loop trough parameter names, store matching value in $params array
             foreach ($param_keys as $key) {
                 if (isset($params[$key])) {
-                    $url = preg_replace('/:(\w+)/', $params[$key], $url, 1);
+                    $url = preg_replace('/:'.preg_quote($key).'/', $params[$key], $url, 1);
                 }
             }
         }