adrienlucbert / php-router
PHP的极简路由框架,受ExpressJS启发。
v1.2
2021-01-04 15:29 UTC
Requires
- php: >=5.3.0
This package is auto-updated.
Last update: 2024-09-04 23:52:13 UTC
README
本项目是一个受ExpressJS启发的PHP极简路由框架。
安装
使用composer管理依赖并下载PHP Router。
composer require adrienlucbert/php-router
示例
ℹ️ 更多示例在
/examples
目录下
⚠️ 您也可以使用
.htaccess
文件将所有请求重定向到单个文件。此文件将负责描述路由:在这个示例中,我们称它为index.php
,但您可以根据需要命名,只需确保.htaccess
文件将其重定向到它即可。
<?php // use composer autoload to include package files require __DIR__ . '/vendor/autoload.php'; // alias \PHPRouter\App class use \PHPRouter\App; // create an App object, against which you will then register routes $app = new App(); // register a new route to call when requested uri matches '/' in http method GET $app->get('/', function(&$req, callable $next) { // do whatever you want this route to do print_r($req); // execute next route matching the requested uri $next(); }); // execute application mountpoints according to the requested uri $app->execute();