PHP code example of albertoadolfo27 / friendly_route
1. Go to this page and download the library: Download albertoadolfo27/friendly_route 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/ */
albertoadolfo27 / friendly_route example snippets
// Require the Composer autoloader.
nfiguration.
$config = array(
"debug" => true,
"projectDir" => "friendly_route" // Set the Project Directory if you are working on the localhost. Default empty string.
);
// Instantiate a Router.
$router = new Router($config);
// Tracing routes
$router->get("/", function () {
echo "<h1>Hello World!</h1>";
});
$router->get("/user/{username}", function ($args) {
$user = $args["username"];
echo "<h1>Welcome {$user}</h1>";
});
$router->notFound(function () {
echo "<h1>404 NOT FOUND</h1>";
});
$router->run();
$router->get("/", function () {
// Put the code to run
});
$router->set("GET", "/", function () {
// Put the code to run
});
$router->post("/", function () {
// Put the code to run
});
$router->set("POST", "/", function () {
// Put the code to run
});
$router->put("/", function () {
// Put the code to run
});
$router->set("PUT", "/", function () {
// Put the code to run
});
$router->delete("/", function () {
// Put the code to run
});
$router->set("DELETE", "/", function () {
// Put the code to run
});
$router->set(array("GET", "POST"), "/", function () {
// Put the code to run
});
$router->get(["/hello","/hi"], function () {
// Put the code to run
});
$router->methodNotAllowed(function () {
echo "<h1>405 METHOD NOT ALLOWED</h1>";
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.