1. Go to this page and download the library: Download laasti/route 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/ */
laasti / route example snippets
$container = new League\Container;
$routes = new League\Route\RouteCollection($container);
$container->add('Laasti\Route\DefineControllerMiddleware')->withArgument($routes);
$routes->setStrategy(new Laasti\Route\ControllerDefinitionStrategy);
$request = Symfony\Component\HttpFoundation\Request::create('/test');
$routes->get('/test', 'MyController::display');
$resolver = new Laasti\Stack\ContainerResolver($container);
$stack = new Laasti\Stack\Stack($resolver);
$stack->push('Laasti\Route\DefineControllerMiddleware');
$stack->push('Laasti\Route\CallControllerMiddleware');
$stack->execute($request);
$container = new League\Container;
$routes = new League\Route\RouteCollection($container);
$routes->setStrategy(new Laasti\Route\ControllerDefinitionStrategy);
$request = Symfony\Component\HttpFoundation\Request::create('/test/George');
$routes->get('/test/{name}', 'MyController::display');
$definition = $routes->getDispatcher()->dispatch($request->getMethod(), $request->getPathInfo());
//Pass the request or any arguments to the controller
//Calls MyController->display($request);
$request->attributes->add($definition->getArguments());
echo $definition->callController($request);
//Or, uses route attributes as arguments
//Calls MyController->display($name);
echo $definition->callController();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.