Dynamic Placeholder-based Route Patterns(Named Params)
Dynamic routing with named parameters


Named Params

This guide assumes you have read Simple Routing

Basically, Dynamic Placeholder-based Route Patterns are just another way to use routes dynamically. This type of Route Patterns are the same as Dynamic PCRE-based Route Patterns, but with one difference: they don't use regexes to do the pattern matching but they use the more easy placeholders instead. Placeholders are strings surrounded by curly braces, e.g. {name}. You don't need to add parens around placeholders.


  • /movies/{id}
  • /profile/{username}

Placeholders are easier to use than PRCEs, but offer you less control as they internally get translated to a PRCE that matches any character (.*).

$leaf->get('/movies/{movieId}/photos/{photoId}', function($movieId, $photoId) { echo 'Movie #' . $movieId . ', photo #' . $photoId); });

Note: the name of the placeholder does not need to match with the name of the parameter that is passed into the route handling function...although it's adviced:

$leaf->get('/movies/{foo}/photos/{bar}', function($movieId, $photoId) { echo 'Movie #' . $movieId . ', photo #' . $photoId); });

Next Steps

Optional sub-patterns
Simple Authentication