Skip to content

Route Controller Types

Devin Smith edited this page Dec 11, 2015 · 3 revisions

Route controllers can be closure functions, class names, controllers, class instances, or anonymous classes.

Closure Function
$tipsy->router()
	->when('/about', function() {
		echo 'This is us!';
	});
Class Name
// Define the Class
class ClassController extends Tipsy\Controller {
	public function init() {
		echo 'This is a class';
	}
}

// Set the route
$tipsy->router()
	->when('about', [
		'controller' => 'LibraryController'
	]);
Controller
// Define the Controller
$tipsy->controller('InternalController', function() {
	echo 'This is an internal Controller';
});

// Set the route
$tipsy->router()
	->when('about', [
		'controller' => 'InternalController'
	]);
Class Instance
// Define the Controller
class InstanceController extends Tipsy\Controller {
	public function init() {
		echo 'This is a instance';
	}
}

// instantiate object
$instance = new InstanceController;

// Set the route
$tipsy->router()
	->when('about', [
		'controller' => $instance
	]);
Anonymous Class
$tipsy->router()
	->when('some/page', new class() extends Tipsy\Controller {
		public function init() {
			echo 'Page';
		}
	});