A simple PHP Router

Related tags

Routers panda-router
Overview

Panda Router

Description

the panda-router is a small alternative PHP router that can be used for small projects. With this router you can use different HTTP methods. For example GET and POST but also PUT, PATCH and DELETE. Furthermore a 404 (default) route can be created.

The routes work with simple functions as well as with functions that are in objects.

How to integrate the panda router in your Project

First Step

include and modify the htaccess file

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /projectFolder/index.php [L]

Secound Step

add the class PandaRouter (PandaRouter.php) to your project and then include it in your index page

#index.php (example)
require_once __DIR__ . '/PandaRouter.php';
$router = new PandaRouter;

Third Step

create the routes

OPTION A

Routes by functions

#index.php (example)
require_once __DIR__ . '/PandaRouter.php';
$router = new PandaRouter;

$demo = function () {
    echo 'Demo';
};

$error = function () {
    echo 'Error';
};

$router->get('/demo/', null, $demo);
$router->default(null, $error);

OPTION B

Routes by functions in Objects

#index.php (example)
require_once __DIR__ . '/PandaRouter.php';
require_once __DIR__ . '/DemoController.php';

$controller = new DemoController;
#Static GET-Route
$router->get('DOMAIN/route/', 'object | class', 'method',['optionalParams']);

#Dynamic GET-Route
$router->get('DOMAIN/route/:param1,param2,...', 'object | class', 'method',['optionalParams']);

#POST-Route
$router->post('DOMAIN/route/', 'object | class', 'method',['optionalParams']);

#PUT-Route
$router->put('DOMAIN/route/', 'object | class', 'method',['optionalParams']);

#PATCH-Route
$router->patch('DOMAIN/route/', 'object | class', 'method',['optionalParams']);

#DELETE-Route
$router->delete('DOMAIN/route/', 'object | class', 'method',['optionalParams']);

#DEFAULT-Route (404-ROUTE)
$router->default('object | class', 'method');

Last Step

Start the Router

#index.php (example)
... OPTION A OR OPTION B ...

$router->run();

created by JP Behrens

If you have any suggestions for improvement or ideas for extension. please let me know.

[email protected]

You might also like...
Toro is a PHP router for developing RESTful web applications and APIs.

Toro Toro is a PHP router for developing RESTful web applications and APIs. It is designed for minimalists who want to get work done. Quick Links Offi

PhpRouter is a powerful, lightweight, and very fast HTTP URL router for PHP projects.

PhpRouter PhpRouter is a powerful, lightweight, and very fast HTTP URL router for PHP projects. Some of the provided features: Route parameters Predef

A lightweight and fast router for PHP
A lightweight and fast router for PHP

Piko Router A lightweight and blazing fast router (see benchmarks) using a radix trie to store dynamic routes. This router maps routes to user defined

Thruway - an open source client and router implementation of WAMP (Web Application Messaging Protocol), for PHP.

PHP Client and Router Library for Autobahn and WAMP (Web Application Messaging Protocol) for Real-Time Application Messaging

PHPRouter is an easy-to-use, fast, and flexible PHP router package with express-style routing.

PHP-Router is a modern, fast, and adaptable composer package that provides express-style routing in PHP without a framework.

A lightweight and very basic PHP router.

Katya A lightweight PHP router Configuration Para servidor Apache, en el directorio del proyecto crea y edita un archivo .htaccess con lo siguiente:

A PHP Router Package

Router A PHP Router Package Basic Concepts A router package is a utility that, once all http requests are redirected to an entry point, can configure

A fast & flexible router

Klein.php klein.php is a fast & flexible router for PHP 5.3+ Flexible regular expression routing (inspired by Sinatra) A set of boilerplate methods fo

A router for Amp's HTTP Server.

http-server-router This package provides a routing RequestHandler for Amp's HTTP server based on the request URI and method based on FastRoute. Instal

Owner
Jan Behrens
Jan Behrens
A lightweight and simple object oriented PHP Router

bramus/router A lightweight and simple object oriented PHP Router. Built by Bram(us) Van Damme (https://www.bram.us) and Contributors Features Support

Bramus! 935 Jan 1, 2023
Flight routing is a simple, fast PHP router that is easy to get integrated with other routers.

The PHP HTTP Flight Router divineniiquaye/flight-routing is a HTTP router for PHP 7.1+ based on PSR-7 and PSR-15 with support for annotations, created

Divine Niiquaye Ibok 16 Nov 1, 2022
Simple, fast and yet powerful PHP router that is easy to get integrated and in any project.

Simple, fast and yet powerful PHP router that is easy to get integrated and in any project. Heavily inspired by the way Laravel handles routing, with both simplicity and expand-ability in mind.

Simon Sessingø 472 Jan 4, 2023
A simple PHP Router

Panda Router Description the panda-router is a small alternative PHP router that can be used for small projects. With this router you can use differen

Jan Behrens 1 Dec 27, 2021
The simple PHP router

Macaw Macaw is a simple, open source PHP router. It's super small (~150 LOC), fast, and has some great annotated source code. This class allows you to

Noah Buscher 895 Dec 21, 2022
klein.php is a fast & flexible router for PHP 5.3+

Klein.php klein.php is a fast & flexible router for PHP 5.3+ Flexible regular expression routing (inspired by Sinatra) A set of boilerplate methods fo

null 2.6k Jan 7, 2023
Fast request router for PHP

FastRoute - Fast request router for PHP This library provides a fast implementation of a regular expression based router. Blog post explaining how the

Nikita Popov 4.7k Dec 23, 2022
Pux is a fast PHP Router and includes out-of-box controller tools

Pux Pux is a faster PHP router, it also includes out-of-box controller helpers. 2.0.x Branch Build Status (This branch is under development) Benchmark

Yo-An Lin 1.3k Dec 21, 2022
A web router implementation for PHP.

Aura.Router Powerful, flexible web routing for PSR-7 requests. Installation and Autoloading This package is installable and PSR-4 autoloadable via Com

Aura for PHP 469 Jan 1, 2023
:tada: Release 2.0 is released! Very fast HTTP router for PHP 7.1+ (incl. PHP8 with attributes) based on PSR-7 and PSR-15 with support for annotations and OpenApi (Swagger)

HTTP router for PHP 7.1+ (incl. PHP 8 with attributes) based on PSR-7 and PSR-15 with support for annotations and OpenApi (Swagger) Installation compo

Sunrise // PHP 151 Jan 5, 2023