1. Go to this page and download the library: Download mindplay/timber library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mindplay / timber example snippets
use mindplay\timber\Router;
use mindplay\timber\Result;
use mindplay\timber\Error;
s')->get(ListNews::class);
// Defining route for several HTTP methods
$router->route('/')->get(ShowHomePage::class)->post(PostComments::class);
// Defining a route with regular expression param
$news_route = $router->route('news/<id:^[0-9]+$>')->get(ShowNews::class);
// Defining another route with symbolic param
$router->route('users/<username:slug>')->get(ShowUser::class);
// Defining static route that conflicts with previous route, but static routes have high priority
$router->route('news/all')->get(ShowAllNews::class);
// Defining a wildcard route, matching e.g. "categories/foo", "categories/foo/bar", etc.:
$router->route('categories/<path:*>')->get(ShowCategory::class);
// Resolve HTTP method and URL:
$method = 'GET';
$url = '/news/1';
$result = $router->resolve($method, $url);
if ($result instanceof Error) {
header("HTTP/1.1 {$result->status} ${result->message}");
// ...error response here...
return;
} else {
// ...dispatch $result->handler with $result->params...
}