title: Basic URL routing with parameters
body: <p>I'm trying to build my own Routing classes to better understand PHP frameworks and to work with the MVC pattern.
  I've successifully built a routing system that can instantiate a controller and call a method from that particular controller.</p>
  <p>My problem is now that I can't figure out how to call controller methods with parameters in the &quot;pretty&quot; url, like symfony does as I tried to understand.</p>
  <p>I'm at this point:</p>
  <pre><code>$routes = &quot;get&quot;   =&gt; [
          &quot;/&quot;                 =&gt; [HomeController::class,        &quot;index&quot;],
          &quot;/users&quot;            =&gt; [UsersController::class,       &quot;index&quot;],
          &quot;/users/edit&quot;       =&gt; [UsersController::class,       &quot;edit&quot;],
  ];
  $response = $routes[$method][$path];
  
  class Router { 
  ....
  public function dispatch($response) {
          $controller = $response[0];
          $action = $response[1];
          $params = [];
          $instance = new $controller();
          call_user_func_array([$instance, $action], $params);
      }
  }
  </code></pre>
  <p>I would somehow like to add a third parameter to the $routes['get'] like this:</p>
  <pre><code>&quot;/users/{user_id}/edit&quot;       =&gt; [UsersController::class, &quot;edit&quot;, [{user_id}],
  </code></pre>
  <p>and then instantiate my controller calling the edit method with $user_id as a parameter</p>
  <pre><code>class Router { 
  ....
  public function dispatch($response) {
          $controller = $response[0];
          $action = $response[1];
          $params = $response[2];
          $instance = new $controller();
          call_user_func_array([$instance, $action], $params);
      }
  }
  
  class UsersController extends Controller {
  ....
  
  public function edit($user_id){
          echo &quot;Editing $user_id&quot;;
      }
  }
  </code></pre>