1. Go to this page and download the library: Download puz/router 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/ */
puz / router example snippets
use \Puz\Router\Router;
$router = new Router;
// ...
// Adding a new one
Router::registerValidator(MyValidatorClass::class);
// Replacing the list and then add a new one
Router::registerValidator(MyValidatorClass::class, true);
// ...
$router->post("/support")->callback(function() {
// Send email to support
});
// You can create parameters by using ":" followed by letters a-z
$router->get("/hello-:name", function ($name) {
echo "Hello, $name";
});
// ...
// Ugly code to remove the subfolders.
// Got a cleaner and more understandable way? Give me a ping
$url = explode("/".trim(str_replace($_SERVER['DOCUMENT_ROOT'], "", dirname($_SERVER['SCRIPT_FILENAME'])), "/"), $_SERVER['REQUEST_URI'], 2)[1];
$router->run([
'method' => $_SERVER['REQUEST_METHOD'],
'url' => $url
]);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.