Modern PHP Routing System

A lightweight, flexible routing solution for your PHP applications

Routing System Showcase

How It Works

This routing system provides a clean, elegant way to define routes in your PHP application. It supports controller-based routing, middleware, and different HTTP methods.

// Define routes in routes/web.php $router->get('/', 'HomeController@index'); $router->get('/about', 'PageController@about'); $router->post('/contact', 'ContactController@submit'); // Protected route with middleware $router->get('/dashboard', 'DashboardController@index', ['auth']);

Key Features

  • Simple Routing

    Define routes with HTTP methods, URIs, and handlers

  • Middleware Support

    Add authentication, validation, and other middleware

  • Controller Integration

    Organize your code with controller classes

  • Error Handling

    Clean error responses with proper HTTP status codes

Route Examples

Method URI Handler Middleware
GET / HomeController@index -
GET /about PageController@about -
POST /login AuthController@login guest
GET /dashboard DashboardController@index auth
POST /api/users ApiController@createUser auth, json
DELETE /api/users/{id} ApiController@deleteUser auth, json

Implementation Example

// In a controller file class HomeController { public function index() { // Load homepage view require_once __DIR__ . '/../views/home.php'; } public function about() { // Load about page view require_once __DIR__ . '/../views/about.php'; } }

Why Choose This Routing System?

Designed for simplicity, flexibility, and performance

Lightweight & Fast

Minimal overhead with optimized performance for quick response times.

Easy to Customize

Simple structure makes it easy to extend and adapt to your specific needs.

Secure by Design

Built with security best practices to protect your application.

Getting Started

1. Define Your Routes

// routes/web.php $router->get('/', 'HomeController@index'); $router->get('/about', 'PageController@about'); $router->post('/contact', 'ContactController@submit');

2. Create Your Controllers

// app/Controllers/HomeController.php class HomeController { public function index() { require_once __DIR__ . '/../views/home.php'; } }

3. Add Middleware (Optional)

// Define middleware in Middleware.php class Middleware { public static function auth() { if (!isset($_SESSION['user'])) { header('Location: /login'); exit(); } return true; } } // Apply middleware to routes $router->get('/dashboard', 'DashboardController@index', ['auth']);