1. Go to this page and download the library: Download ahmard/quick-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/ */
ahmard / quick-route example snippets
use QuickRoute\Route;
use QuickRoute\Router\Dispatcher;
);
$method = $_SERVER['REQUEST_METHOD'];
$path = $_SERVER['REQUEST_URI'];
//create route dispatcher
$dispatcher = Dispatcher::collectRoutes()
->dispatch($method, $path);
//determine dispatch result
switch (true) {
case $dispatcher->isFound():
$controller = $dispatcher->getRoute()->getController();
$controller($dispatcher->getUrlParameters());
break;
case $dispatcher->isNotFound():
echo "Page not found";
break;
case $dispatcher->isMethodNotAllowed():
echo "Request method not allowed";
break;
}
use QuickRoute\Route;
Route::get('/home', 'MainController@home');
use QuickRoute\Route;
// id => must be number
Route::get('users/{id}', 'Controller@index')->whereNumber('id');
// name => must be alphabetic
Route::get('users/{name}', 'Controller@profile')->whereAlpha('name');
// username => must be alphanumeric
Route::get('users/{username}', 'Controller@profile')->whereAlphaNumeric('username');
// Manually provide regular expression pattern to match parameter with
Route::get('/users/{id}', 'a')->where('id', '[0-9]+');
Route::get('/users/{user}/posts/{post}', 'Ctrl@method')->where([
'user' => '[a-zA-Z]+',
'post' => '[0-9]+'
]);