PHP code example of cutplane1 / u-router
1. Go to this page and download the library: Download cutplane1/u-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/ */
cutplane1 / u-router example snippets
er = new Cutplane1\URouter();
$router->not_found(function() {
http_response_code(404);
echo "<h1>404 Not Found</h1>";
});
$router->middleware(function() {
header('Content-Type: application/json; charset=utf-8');
});
$router->get("/", function() {
echo json_encode(["hello" => "world"]);
});
$router->get("/<int>", function($id) {
echo json_encode(["id" => $id]);
});
$router->dispatch();