Routing

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.

Defining routes

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']
    ]);

Placeholders

<?php
$routeCollection
->get('/:name');

Optonal placeholders

<?php
$routeCollection
->get('/(:name)');

Optional placeholders default values

<?php
$routeCollection
->get('/(:name)')
    ->
defaults([
        
'name' => 'world',
    ]);

Placeholders constraints

<?php
$routeCollection
->get('/:name')
    ->
constraints([
        
'name' => '[a-zA-Z]+',
    ]);

Accept multiple http methods

<?php
$routeCollection
->addRoute('/:name')
    ->
allows(['GET''POST']);

I18n routes

<?php
$routeCollection
->get('/hello')
    ->
i18n([
        
'fr' => '/bonjour',
        
'nl' => '/hallo',
    ]);

Dispatching

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.