1. Go to this page and download the library: Download wepesi/routing 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/ */
wepesi / routing example snippets
// Require composer autoloader
uter = new \Wepesi\Routing\Router();
// Define routes
// ...
// Run it!
$router->run();
// This route handling function will only be executed when visiting http(s)://www.example.org/about
$router->get('/about', function() {
echo 'About Page Contents';
});
// This route handling function will only be executed when visiting http(s)://www.example.org/movies/3
$router->get('/movies/:id', function($id) {
echo 'Get a movie by ID:'.$id;
})->with('id','[0-9]+');
$router->group('/movies', function() use ($router) {
// will result in '/movies/'
$router->get('/', function() {
echo 'movies overview';
});
// will result in '/movies/id'
$router->get('/:id', function($id) {
echo 'movie id ' . $id;
});
});
$router->group('/articles', function() use ($router) {
// will result in '/articles/'
$router->get('/', function() {
echo 'articles overview';
});
//
$router->group('/themes', function() use ($router) {
// will result in '/articles/themes'
$router->get('/', function() {
echo 'Articles themes overview';
});
// will result in '/articles/themes/4'
$router->get('/:id', function($id) {
echo 'Articles themes detail id: ' . $id;
});
});
});
$router->get('/articles/:id', function($id) {
echo "article id is:".$id;
})->middleware(function($id){
if(!filter_var($id,FILTER_VALIDATE_INT)){
echo "you should provide an integer";
exit;
}
});
$router->get('/admin/:id', function($id) {
echo "admin id is:".$id;
})->middleware(function($id){
print_r("First middleware");
})->middleware(function($id){
print_r("Second middleware");
})->middleware(function($id){
print_r("Last middleware before Route function");
});