1. Go to this page and download the library: Download laudirbispo/easy-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/ */
laudirbispo / easy-route example snippets
use laudirbispo\EasyRouter\EasyRouter;
use laudirbispo\EasyRouter\Exceptions\RouterException;
$router = new EasyRouter();
/**
* @param $pattern - string|array routes - accept multiple routes
* @param $calback - class with method string|closure
*/
$router->add($pattern, $callback);
//Examples
$router->add(
['/admin/login', '/admin/login?(.*)'],
'app\IdentityAccess\Application\Controllers\AccountController::pageLogin'
);
// (.*) that is to say that it accepts any parameter after "?"
// example - /admin/login?return=other_url
// Closures and Regular expressions
$router->add(['/admin/users/group/edit/([-\w]{36}$)'], function ($groupId){
$controller = new app\IdentityAccess\Application\Controllers\AdminGroups;
$controller->pageEditGroup($groupId);
});
// For example, this regular expression, accepts only string in the format "4d428391-8975-4158-b68a-9e3054e3df2c"
// "4d428391-8975-4158-b68a-9e3054e3df2c" is uuid4 string
// Other example
$router->add('news/(\w+)/(\d+)', function($category, $year){
$controller = new app\News\Application\Controllers\News;
$controller->getNewsByYear($category, $year);
});
// Check if router exists
$router->has(string $pattern);
// Execute
$router->execute($_SERVER['REQUEST_URI']);
// Exeptions
// RouterException
// ControllerDoesNotExists
// InvalidRoute
// MethodDoesNotExists
// RouteNotFound
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.