1. Go to this page and download the library: Download niirrty/niirrty.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/ */
niirrty / niirrty.routing example snippets
use \Niirrty\Routing\UrlPathLocator\RequestUri as RequestUriLocator;
use \Niirrty\Routing\UrlPathLocator\ILocator;
// Get the current called not existing URL path by $_SERVER[ 'REQUEST_URI' ]
$urlPathLocator = new RequestUriLocator();
// Init the router and chain all echo 'Invalid request!';
exit;
} )
// Redirect all index calls to '/' (home call)
->addMultiPathStaticRedirection(
[ '/app.php', '/index.html', '/start.php', '/start.html', '/home.php', '/start.html' ],
'' )
// Home call
->addSimpleRoute(
'/',
function( ILocator $locator )
{
// TODO: show the home
} )
// handling '/services/*' calls
->addRegexRoute(
'~^/services/([A-Za-z0-9_.:-]+)/?$~',
[
function( $matches )
{
// TODO: $matches[ 1 ] defines the first part inside parenthesis, and so on
echo '<pre>';
print_r( $matches );
exit;
}
] )
// add an simple route for showing the impressum
->addSimpleRoute( '/impressum', function( ILocator $locator )
{
// TODO: show the impressum
} );
// Call the router with current locator => Done
$router->call( $urlPathLocator );