PHP code example of jp-codeplus / hazel-router

1. Go to this page and download the library: Download jp-codeplus/hazel-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/ */

    

jp-codeplus / hazel-router example snippets




// Basic Router-Initialisierung
$router = new JayPiii\HazelRouter();
$routerPath = __DIR__ . '/routes.php'; // ==> DEMO ROUTES

$router->createSitemap('/sitemap.xml', 'http://hazel-router.test');

$router->loadRoutes($routerPath);

$router->middleware('myMiddleware', [DemoMiddleware::class, 'index']);

$router->run();

if ($router->displayErrors() !== null) {
    echo $router->displayErrors();
}



// Basic Router
$router = new JayPiii\HazelRouter();
$routerPath = __DIR__ . '/routes.php'; // ==> DEMO ROUTES
$router->createSitemap('/sitemap.xml', 'http://hazel-router.test');
$router->loadRoutes($routerPath);
$router->middleware('myMiddleware', [DemoMiddleware::class, 'index']);
$router->run();

if ($router->displayErrors() !== null) {
    echo $router->displayErrors();
}

return [
    [
        'uri' => '/',
        'action' => [DemoController::class, 'index'],
        'method' => 'GET',
        'middleware' => ['myMiddleware'],
        'sitemap' => true,
        'visibility' => 'live'
    ],
    [
        'uri' => '/hello',
        'action' => [DemoController::class, 'hello'],
        'method' => 'GET',
        'middleware' => [],
        'sitemap' => false,
        'visibility' => 'staging'
    ],
    [
        'uri' => '/mellow',
        'action' => [DemoController::class, 'mellow'],
        'method' => 'GET',
        'middleware' => [],
        'sitemap' => true,
        'visibility' => 'live'
    ],
];