chahal26/php-simple-router
最新稳定版本:2.0
Composer 安装命令:
composer require chahal26/php-simple-router
包简介
Simple Routing made with OOPS in PHP
README 文档
README
A simple & lightweight PHP Router made with Object Oriented PHP. Built with ❤️ by Sahil Chahal
It currently supports static routes only.
Prerequisites/Requirements
- PHP >= 8.0
- URL Rewriting
Installation
chahal26/php-simple-router can be easily installed using
composer require chahal26/php-simple-router
Usage
Create an instance of \Chahal26\PhpSimpleRouter\Router, define some routes, and run it.
require_once 'vendor/autoload.php'; use Chahal26\PhpSimpleRouter\Router; /* Creating Route Instance */ $router = new Router(); /* Defining Routes */ /* Execute Routes */ $router->run();
Available Routing Methods
- GET
- POST
Defining Routes
Static Routes
$router->get('route', function() { /* ... */ }); $router->post('route', function() { /* ... */ });
With Controller
$router->get('/about', '\App\Controllers\PagesController@about');
Or a namespace can also be defined
$router->setNamespace('\App\Controllers'); $router->get('/about', 'PagesController@about');
Example
$router->get('/', function(){ echo "<h1>Welcome To Home Page</h1>"; }); $router->get('/contact', function(){ echo "<h1>Welcome To Contact Page</h1>"; });
统计信息
- 总下载量: 38
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-01-12