-
Notifications
You must be signed in to change notification settings - Fork 0
Router
Tux Solbakk edited this page Apr 18, 2017
·
1 revision
<?php
$router = Router::getInstance();
$router->setCanvas('pc');
// Use template called main.php for top level page.
$router->bind('pc', '', function () use ($router) {
return $router->setTemplate('main');
});
// Match url starting with article, and then have one part after.
// eg: article/my-article
$router->bind('pc', ':template/:id', function () use ($router) {
return $router->setTemplate('article');
}, ['template' => 'article', 'id' => '[^/]+']);
// Match url starting with article, and then have any number of parts after.
// eg article/2017/my-article
$router->bind('pc', ':template/:id', function () use ($router) {
return $router->setTemplate('article');
}, ['template' => 'article', 'id' => '.*']);
// Match url starting with article, and then have zero or one part after.
// eg article or article/my-article
$router->bind('pc', ':template(/:id)', function () use ($router) {
return $router->setTemplate('article');
}, ['template' => 'article', 'id' => '[^/]+']);
$router->dispatch();
By default the router will route requests of type GET and HEAD. To override this you can specify any other request method like so:
<?php
$router->bind('pc', ':template/:id', function () use ($router) {
return $router->setTemplate('article');
}, ['template' => 'feedback', 'id' => '[^/]+'], Router::R_POST);