1. Go to this page and download the library: Download solophp/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/ */
solophp / router example snippets
use Solo\Router\RouteCollector;
$router = new RouteCollector();
// Invokable controller
$router->get('/users', UserController::class);
// Traditional controller with method
$router->get('/users', [UserController::class, 'index']);
// Named routes
$router->get('/users/{id}', [UserController::class, 'show'])->name('users.show');
// Optional parameters
$router->get('/posts[/{page}]', [PostController::class, 'index']);
// With middleware and page attribute
$router->post('/admin/posts', [PostController::class, 'store'],
[AuthMiddleware::class],
'admin.posts'
);
// Route groups
$router->group('/admin', function(RouteCollector $router) {
$router->get('/dashboard', [AdminController::class, 'dashboard']);
$router->get('/users', [AdminController::class, 'users']);
}, [AuthMiddleware::class]);
// Match route
$route = $router->matchRoute('GET', '/users/123');
if ($route) {
// Handle the route
$handler = $route['handler'];
$args = $route['args']; // ['id' => '123']
$middleware = $route['middleware'];
$page = $route['page']; // Optional page identifier
}