-
Notifications
You must be signed in to change notification settings - Fork 10
Built in Services
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.
Allows access to the view renderer. For more information see Views.
$tipsy->router()
->when('', function($View) {
$View->display('home');
});
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>
Direct access to the Tipsy object.
$tipsy->router()
->when('debug', function($Tipsy) {
var_dump($Tipsy->config());
});
Direct access to the current route
$tipsy->router()
->when('debug', function($Route) {
var_dump($Route);
});
Access to route params. Anything that starts with ":" will populate this service.
$tipsy->router()
->when('user/:id', function($Params) {
echo $Params->id;
});
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
$tipsy->router()
->get('/', function($Request) {
echo $Request->var;
});
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');
- Home
- Getting Started
- Server Config
- Installation
- Installing Composer
- App
- Route Shorthand
- Config
- Routes
- Methods
- Controller Types
- Params & Regex
- Aliases
- Dependency Injection
- Advanced Routing
- Services
- User Defined Services
- Built in Services
- Middleware
- Views
- Templates
- Scope
- Resource
- Factory
- Looper
- Examples
- Plugins
- About