Skip to content
Devin Smith edited this page Jan 21, 2016 · 42 revisions

Methods

The router supports any amount of routes, methods, and can be chained.

$tipsy->router()->get('hello', function() {
	echo 'World';
});

See Route Methods for more information. For more control on routes see Advanced Routing.


Controllers

A route controller can be a closure function, class name, tipsy controller, class instance, or anonymous class.

$tipsy->router()->when('some/page', new class() extends Tipsy\Controller {
	public function init() {
		echo 'Page';
	}
});

See Controller Types for more information.


Route Params

Routes accept colon delimited params, as well as regex routes.

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

See Route Params for more information.


Method Chaining

The router methods return the router object to allow chaining.

$tipsy->router()
	->home(function() {
		echo 'Sup home boy';
	})
	->when('cats', function() {
		echo 'Every kind of cat.';
	})
	->otherwise(function() {
		echo '404';
	});

Dependency Injection

All controllers support Dependency Injection of both User Defined Services and Built in Services.

$tipsy->router()
	->when('user/:id', function($Params, $View) {
		$View->display('home', ['user' => $Params->id]);
	});

See Dependency Injection for more information.


Route Aliases

Routes can be mapped from one route to another.

$tipsy->router()
	->when('item/edit/:id', function($Params) {
		echo $Params->id;
	})
	->alias('item/:id/edit', 'item/edit/:id');

See Route Aliases for more information.


Routing URLs

Tipsy will either read your $_SERVER['REQUEST_URI'], or a $_REQUEST['__url'] variable.

For more information on how to set up routing, see Server Config