penobit/irouter 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

penobit/irouter

Composer 安装命令:

composer require penobit/irouter

包简介

A lightning fast router for PHP

README 文档

README

Build Status Latest Stable Version License

Installation

You can install this package using composer or download last release from github and include the iRouter.php file But i strongly recommend using composer For installing package using composer use this command

composer require penobit/irouter

Requirements

You need PHP >= 5.6 to use iRouter, although we highly recommend you use an officially supported PHP version that is not EOL.

Features

  • Can be used with all HTTP Methods
  • Dynamic routing with named route parameters
  • Reversed routing
  • Flexible regular expression routing
  • Custom regexes

Examples

Adding a route

$router = new iRouter();

// map homepage
$router->map('GET', '/', function() {
    require __DIR__ . '/views/home.php';
});

Adding multiple routes at once

// Add multiple routes
$router->addRoutes(array(
  array('GET','/users/[i:id]', 'users#get', 'update_user'),
  array('PUT','/users/[i:id]', 'users#create', 'update_user'),
  array('PATCH','/users/[i:id]', 'users#update', 'update_user'),
  array('DELETE','/users/[i:id]', 'users#delete', 'delete_user')
));

Dynamic routes (with parameters)

// dynamic named route
$router->map('GET|POST', '/users/[i:id]/', function($id) {
  $user = .....
  require __DIR__ . '/views/user/details.php';
}, 'user-details');

Generate url by named routes

// echo URL to user-details page for ID 5
echo $router->generate('user-details', ['id' => 5]); // Output: "/users/5"

Match types

Adding match types

// Add match type
$router->addMatchTypes(array('customType' => '[a-zA-Z]{2}[0-9]?'));
$router->map('GET', '/use-match-type/[customType:paramName]', function() {
    require __DIR__ . '/views/home.php';
});

Default match types

*                    // Match all request URIs
[i]                  // Match an integer
[i:id]               // Match an integer as 'id'
[a:action]           // Match alphanumeric characters as 'action'
[h:key]              // Match hexadecimal characters as 'key'
[:action]            // Match anything up to the next / or end of the URI as 'action'
[create|edit:action] // Match either 'create' or 'edit' as 'action'
[*]                  // Catch all (lazy, stops at the next trailing slash)
[*:trailing]         // Catch all as 'trailing' (lazy)
[**:trailing]        // Catch all (possessive - will match the rest of the URI)
.[:format]?          // Match an optional parameter 'format' - a / or . before the block is also optional

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-07-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固