PHP code example of mamphir / extreemly-simple-router
1. Go to this page and download the library: Download mamphir/extreemly-simple-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/ */
mamphir / extreemly-simple-router example snippets
//import Router class
Router
$router = new \ESRouter\Router();
//define new route
$router->addRoute("/user/{name}/post/{id:[0-9]}", "get", function ($args) {
//handle request as you need
$name = $args['name'];
$id = $args['id'];
print $name.$id ;
});
//define another route
$router->addRoute("/", "get", function ($args) {
//handle request as you need
print "Welcome home" ;
});
//more routes
//...
//optional
//Setting 404 handler
$router->setE404(function(){
echo "this is 404";
});
$router->run();
//Example
//In this case if we call http://<server>/user/nameOfTheUser/post/1234
$router->addRoute("/user/{name}/post/{id:\d{4}}", "get", function ($args) {
print 'First route';
});
$router->addRoute("/user/{name}/post/{id:[0-9]}", "get", function ($args) {
print 'Second route';
});
//First Route will be called
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.