Skip to content
Devin Smith edited this page Jul 31, 2014 · 19 revisions

Tipsy uses Dependency Injection to allow easy access to services.

Available Services

View

Allows access to the view renderer. For more information see Views.

$tipsy->router()
	->when('', function($View) {
		$View->display('home');
	});

Scope

The scope of the view. All variables are passes by reference to allow two way data binding. For more information see Views.

// Router PHP
$tipsy->router()
	->when('chat', function($Scope, $View) {
		$Scope->message = 'Hello!';
		$View->display('chat'); // will output "<b>Hello!</b>"
		echo $Scope->message; // will output "Goodbye!"
	});
// Chat PHTML
<b><?=$message?></b>
<? $message = 'Goodbye!'?>

Tipsy

Direct access to the Tipsy object.

$tipsy->router()
	->when('debug', function($Tipsy) {
		var_dump($Tipsy->config());
	});

Route

Direct access to the current route

$tipsy->router()
	->when('debug', function($Route) {
		var_dump($Route);
	});

Params

Access to route params. Anything that starts with ":" will populate this service.

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

Request

The HTTP request service. Access to request variables or JSON post data.

$tipsy->router()
	->post('post', function($Request) {
		var_dump($Request); // will print everything typically in $_POST
	});

Clone this wiki locally