Menu

Sub-routing
Creating parent and child routes

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 callback function that's already contained within a preceding $leaf->mount(). Also, Note that nested subroutes currently don't support dynamic url patterns, so, you can only do something like this.

$leaf->mount('/user', function() use ($leaf, $response) { $leaf->get('/', function() use($response) { echo $response->renderMarkup('

no user id

'); }); $leaf->get('/(\d+)', function($id) use($response) { echo $response->renderMarkup("

user $id

"); }); $leaf->mount('/settings', function() use ($leaf, $response) { $leaf->get('/privacy', function() use($response) { echo $response->renderMarkup('Privacy Settings'); }); $leaf->get('/notification', function() use($response) { echo $response->renderMarkup("Notification Settings"); }); }); });

Next Steps

Request
Response
Database connection
Session