1. Go to this page and download the library: Download genesis/test-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/ */
use Genesis\TestRouting\Routing;
Routing::addRoute('home page', '/home');
use Genesis\TestRouting\Routing;
$route = Routing::getRoute('home page');
Output: /home
use Genesis\TestRouting\Routing;
Routing::registerFile('/my-routes.php');
use Genesis\TestRouting\Routing;
$route = Routing::getRoute('home page', function ($url) {
return $url . '?testing=1';
});
Output: /home?testing=1
use Genesis\TestRouting\Routing;
use MyApp\Routing\AppRouter;
$router = new AppRouter($routes);
// As long as it is an iterable, it will do.
$routes = $router->getAll();
Routing::setAllRoutesFromExternalSource($routes, function ($route, $index) {
// $route contains individual elements contained within routes. Just return the name and the url.
return [$route->getName() => $route->getUrl()];
});
Note: You can bypass the above by using the file data directly most of the time.
use Genesis\SQLExtensionWrapper\BaseProvider;
use Genesis\TestRouting\RoutingContext as Routing;
/**
* RoutingContext class.
*/
class RoutingContext extends Routing
{
/**
* @Override The bit that will replace ids n stuff within our routes.
*
* @return callable
*/
protected function getCallable(): callable
{
$sqlApi = BaseProvider::getApi();
return function ($url) use ($sqlApi) {
return $sqlApi->get('keyStore')->parseKeywordsInString($url);
};
}
}
use Genesis\TestRouting\Routing;
$url = Routing::getRoute($pageName, function ($url) use ($sqlApi) {
// Parse out any database keywords with their values from the keystore for dynamic URLs.
return $sqlApi->get('keyStore')->parseKeywordsInString($url);
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.