-
Notifications
You must be signed in to change notification settings - Fork 10
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.
$tipsy->router()
->when('/about', function() {
echo 'This is us!';
});
// 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'
]);
// Define the Controller
$tipsy->controller('InternalController', function() {
echo 'This is an internal Controller';
});
// Set the route
$tipsy->router()
->when('about', [
'controller' => 'InternalController'
]);
// 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
]);
$tipsy->router()
->when('some/page', new class() extends Tipsy\Controller {
public function init() {
echo 'Page';
}
});
- 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