PHP code example of transitive / routing

1. Go to this page and download the library: Download transitive/routing 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/ */

    

transitive / routing example snippets




use Transitive\Core\Presenter;
use Transitive\Routing\ListRouter;
use Transitive\Routing\Route;
use Transitive\Simple\View;

$route = new Route(new Presenter(), new View());
$route->presenter->addData('message', 'Hello from a route');
$route->view->addContent(function (array $data) {
	return $data['message'];
});

$router = new ListRouter();
$router->addRoute('home', $route);

$matched = $router->execute('home');
$matched?->execute();

echo $matched?->getContent()?->asString() ?? '';



use Transitive\Routing\PathRouter;

$router = new PathRouter(
	__DIR__.'/presenters',
	__DIR__.'/views'
);

$route = $router->execute('blog/post');