-
Notifications
You must be signed in to change notification settings - Fork 10
Routes
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.
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.
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.
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';
});
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.
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.
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
- 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