The purpose of routing is to map a URL to a callback or to an array of data, allowing to route the request to the correct resource.
Add route matching the homepage. Http method GET is allowed.
<?php
$routeCollection = new Gobline\Router\RouteCollection();
$routeCollection->get('/');
Map a route to a callback. Http method GET is allowed.
<?php
$routeCollection->get('/', function($request, $response) {
$response->getBody()->write('Hello, world!');
return $response;
});
Map a route to an array of data. Http method GET is allowed.
More on _view param in
Middlewares section.
<?php
$routeCollection->get('/')
->values([
'_view' => ['text/html' => 'view/hello.html.php']
]);
<?php
$routeCollection->get('/:name');
<?php
$routeCollection->get('/(:name)');
<?php
$routeCollection->get('/(:name)')
->defaults([
'name' => 'world',
]);
<?php
$routeCollection->get('/:name')
->constraints([
'name' => '[a-zA-Z]+',
]);
<?php
$routeCollection->addRoute('/:name')
->allows(['GET', 'POST']);
<?php
$routeCollection->get('/hello')
->i18n([
'fr' => '/bonjour',
'nl' => '/hallo',
]);
Gobline's application core is composed by a set of middlewares that process and dispatch the request based on the matched route's data.
To learn more about request dispatching, read the Middlewares section.