webcretaire/diggy-router
Composer 安装命令:
composer require webcretaire/diggy-router
包简介
Simple routing component for PHP
README 文档
README
Simple routing component for php
Installation
Currently the only way of installing is via composer :
composer require webcretaire/diggy-router
Basic Usage
First you have to register the routes you want to use in a YAML file with the following structure :
routes: # First Route - uri: '/addressOfYourPage' controller: 'Name\Of\A\Class' action: 'nameOfTheFunctionToCall' # Second Route - uri: '/addressOfYourSecondPage' controller: 'Name\Of\A\Class' action: 'nameOfTheFunctionToCall' # ...
Note that the "action" parameter is optionnal, if it is not provided the router will try to call a "render()" function with no parameters
Then create a new router :
$router = new DiggyRouter\Router()
Load your routes into the router :
$router->loadRoutes("path/to/your/routing.yml");
Use the router to call the correct function in the correct controller according to the requested URI :
$router->handleRequest();
Advanced usage
By default the router tries to find a route that matches the requested URI which is stored in
$_SERVER['REQUEST_URI'], but you can specify the URI to use by passing it to the function :
$router->handleRequest($customURI);
DiggyRouter now supports multiple URIs for one route, you just have define the uri parameter of your route as an array :
routes: - uri: - '/firstPage' - '/secondPage' controller: 'Name\Of\A\Class' action: 'nameOfTheFunctionToCall' # ...
If you have complex URIs, you can specify an expression that the requested URI must match. The default delimiter is '~' but you can specify which one to use by doing :
$router->setDelimiter('YourDelimiter');
If you have a lot of URIs, you can split your routes between one main routing file and as many secondary files as you want :
# Main routing file includes: - 'secondRoutingFile' - 'thirdRoutingFile' routes: - uri: '/SomeAdditionnalRoutes' controller: 'Name\Of\A\Class' # ...
# Second routing file routes: - uri: '/RoutesEverywhere' controller: 'Name\Of\A\Class' # ...
Examples
You can see a full example in this routing file
webcretaire/diggy-router 适用场景与选型建议
webcretaire/diggy-router 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 143 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 07 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 webcretaire/diggy-router 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 webcretaire/diggy-router 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 143
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-07-21