1. Go to this page and download the library: Download websk/php-simple-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/ */
websk / php-simple-router example snippets
use WebSK\SimpleRouter\SimpleRouter;
final class ArticleController
{
public function show(string $slug): void
{
echo 'Article: ' . htmlspecialchars($slug, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
}
}
SimpleRouter::route(
'~^/articles/([^/]+)$~',
[ArticleController::class, 'show']
);
public function checkAccess(): string
{
// Perform an access check or other intermediate processing.
return SimpleRouter::CONTINUE_ROUTING;
}
if (SimpleRouter::matchGroup('~^/admin(?:/|$)~')) {
SimpleRouter::route('~^/admin/users$~', [AdminUserController::class, 'list']);
SimpleRouter::route('~^/admin/users/(\d+)$~', [AdminUserController::class, 'show']);
}
use WebSK\SimpleRouter\Sitemap\InterfaceSitemapController;
final class ArticleController implements InterfaceSitemapController
{
public function getUrlsForSitemap(): iterable
{
yield [
'url' => 'https://example.com/articles/first',
'freq' => 'weekly',
];
yield [
'url' => 'https://example.com/articles/second',
];
}
}
use WebSK\SimpleRouter\SimpleRouter;
use WebSK\SimpleRouter\Sitemap\SitemapBuilder;
$builder = new SitemapBuilder();
SimpleRouter::setSitemapBuilder($builder);
SitemapBuilder::removeOldSitemapFiles();
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.