Overview
Subrouting
Use $leaf->mount($baseroute, $fn)
to mount a collection of routes onto a subroute pattern. The subroute pattern is prefixed onto all following routes defined in the scope. e.g. Mounting a callback $fn onto /movies will prefix /movies onto all following routes.
$leaf->mount('/movies', function() use ($leaf) {
// will result in '/movies/'
$leaf->get('/', function() {
echo 'movies overview';
});
// will result in '/movies/id'
$leaf->get('/(\d+)', function($id) {
echo 'movie id ' . htmlentities($id);
});
});
Nesting of subroutes is possible, just define a second $leaf->mount() in the callable that's already contained within a preceding $leaf->mount()
.
Next Steps
Re-routing to index.phpSimple Routing
Request
Response