1. Go to this page and download the library: Download nette/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/ */
$params = $router->match($httpRequest);
if ($params === null) {
// no matching route found, we will send a 404 error
exit;
}
// we process the received parameters
$controller = $params['controller'];
...
// accepts both /hello and /hello.html, generates /hello
$router->addRoute('<name>[.html]', ...);
// accepts both /hello and /hello.html, generates /hello.html
$router->addRoute('<name>[!.html]', ...);
$router->addRoute('<controller=Homepage>/<action=default>/<id=>', ...);
// equals to:
$router->addRoute('[<controller=Homepage>/[<action=default>/[<id>]]]', ...);
$router = new Nette\Application\Routers\SimpleRouter();
<IfModule mod_rewrite.c>
RewriteEngine On
...
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
...
</IfModule>
// Will generate an HTTP address
$router->addRoute('http://%host%/<controller>/<action>', ...);
// Will generate an HTTPS address
$router->addRoute('https://%host%/<controller>/<action>', ...);
use Nette\Http\IRequest as HttpRequest;
use Nette\Http\UrlScript;
class MyRouter implements Nette\Routing\Router
{
public function match(HttpRequest $httpRequest): ?array
{
// ...
}
public function constructUrl(array $params, UrlScript $refUrl): ?string
{
// ...
}
}
$router = new Nette\Application\Routers\RouteList;
$router->add(new MyRouter);
$router->addRoute(...);
...
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.