PHP code example of shanta280 / easy_php_router
1. Go to this page and download the library: Download shanta280/easy_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/ */
shanta280 / easy_php_router example snippets
composer
// Shantanu\EasyRouter();
$r->get("/", function() {
echo "Home page";
});
$r->get("/about/{name}", function($name="") {
echo "About {$name}";
});
// good this page will be shown
// when url does not maych any thing
// good for showing 404
$r->get("/{any}", function($any='') {
echo $any;
});
$r->get("/contact", function() {
echo "Contact Page";
});
$r->get("/services", function() {
echo "Services Page";
});
$r->any("/anymethod", function() {
// we can call this route with any method
});
// to set custom 404 page
$r->set404(function() {
die("Custom 404 page");
});
$r->run();// this line is important, it starts the routing process