Skip to content
Devin Smith edited this page Dec 10, 2015 · 7 revisions

Tipsy uses Dependency Injection to allow easy access to services. Services act as static models that are the same instance throughout the Tipsy instance.

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>"
	});
<?/* Chat PHTML */ ?>
<b><?=$message?></b>

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.

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

Request

The HTTP request service. Access to request variables or JSON data. Data is accessible by it's properties/

Methods

  • base() - returns the basepath of the script
  • host() - returns the hostname
  • loc($x) - returns the path piece from the path
  • path() - returns the path of the request
  • url - returns the full path including hostname
GET /?var=test
$tipsy->router()
	->get('/', function($Request) {
		echo $Request->var;
	});
test

Db

Db provides basic database connectivity.

$tipsy->config([db => [url => 'mysql://user:pass@host:port/database']]);
//or
$tipsy->config([db => [
	host => 'host',
	user => 'user',
	pass => 'pass',
	port => 'port',
	database => 'database',
	driver => 'mysql'
]);
$tipsy->db()->query('select * from stuff');