1. Go to this page and download the library: Download obscure-code/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/ */
obscure-code / router example snippets
use ObscureCode\Router as AbstractRouter;
class Router extends AbstractRouter {
public function patternDefault(string $path): void
{
$this->load('header');
$this->load($path);
$this->load('footer');
}
public function patternBlank(string $path): void
{
$this->load($path);
}
public function patternError(string $path): void
{
http_response_code(404);
$this->load('header');
$this->load('error');
$this->load('footer');
}
};
// Call />call('/');
// Call /x');
// If /, 'd', 'e'] will passed in $params
$router->call('/a/b/c/d/e');
// ['data'] will passed in $data
$router->call('/index', ['data']);
public function patternDefault(string $path): void
{
$someClass = new SomeClass();
$this->load('header');
$this->load($path, ['someClass' => $someClass]);
$this->load('footer');
}