Skip to content

Route Params & Regex

Devin Smith edited this page Jan 21, 2016 · 2 revisions

Routes accept params similar to Express Routes.

$tipsy->router()->when('user/:name', function($Params) {
	echo $Params->name;
});

Route Aliases map params based on the Param Name

$tipsy->router()->alias('group/:project/user/:name', 'user/:name');

Routes can also accept a full regex. When a regex is used, params is an array of matches.

$tipsy->router()->when('/^api\/user\/(.*)\/details$/i', function($Params) {
	echo $Params[1]; // the user name of the service
});

Regex is especially useful when catching files that need to render.

$tipsy->router()->when('/\.scss$/i', function($Request) {
	echo $Request->path(); // the requested file
});