1. Go to this page and download the library: Download trulyao/php-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/ */
trulyao / php-router example snippets
use \Trulyao\PhpRouter\Router as Router;
$router = new Router(__DIR__."/views", "demo");
$router->get("/", function($req, $res) {
return $res->send("<h1>Hello World</h1>")
->status(200);
});
$router->get('/render', function ($req, $res) {
return $res->render("second.html", $req);
});
$router->post("/", function($req, $res) {
return $res->send([
"message" => "Hello World"
]);
});
# using a class based controller
$router->delete("/", [new NoteController(), "destroy"]);
$router->route("/chained")
->get(function ($req, $res) {
return $res->send("GET - Chained!");
})
->post(function ($req, $res) {
return $res->send("POST - Chained!");
});
# Start the router - very important!
$router->serve();