webservis / php-router
Simple PHP Router Example
Installs: 16
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/webservis/php-router
Requires
- php: >=7.4
This package is auto-updated.
Last update: 2025-12-05 12:18:53 UTC
README
This is a simple PHP router class that can be used to define routes for web applications.
Usage
-
Installation
First, you need to include the
Route.phpfile in your project. You can do this by copying the content of theRoute.phpfile into your project or by using Composer.composer require webservis/php-router
-
Basic Usage
<?php require_once 'vendor/autoload.php'; // Adjust this based on your project's structure use Webservis\Route; $router = new Route(); $router->get('/', function () { echo "Hello, World!"; }); $router->get('/about', function () { echo "About Us Page"; }); $router->dispatch();
-
Defining Routes
$router->get('/products/:id', function ($id) { echo "Product ID: $id"; })->name('product'); $router->get('/categories/:slug', 'CategoryController@show')->name('category.show');
-
URL Generation
$productUrl = $router->url('product', ['id' => 123]); echo "Product URL: $productUrl";
-
Subdomain Routing
$router->subdomain('admin', function () { Route::get('/dashboard', 'AdminController@dashboard')->name('admin.dashboard'); });
-
Prefix Routing
Route::prefix('/admin/auth')->group(function (){ Route::get('/?', 'Auth@index')->name('auth'); Route::get('/login', 'Auth@login')->name('auth/login'); Route::get('/logout','Auth@logout')->name('auth/logout'); //Route::get('/auth',function(){return 'This page is Authentification page';})->name('auth'); Route::redirect('/auth/signin','/auth/login'); });
-
Read More
For more details and advanced usage, please refer to the documentation in the
docsdirectory.