定制 dv-team/router 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

dv-team/router

Composer 安装命令:

composer require dv-team/router

包简介

A simple routing library

README 文档

README

Usage Documentation for Router Class

The Router class is used to define and manage routes in a PHP application. It allows you to define routes for different HTTP methods and generate URLs based on these routes.

Example usage:

use DvTeam\Routing\Router;
use Psr\EventDispatcher\EventDispatcherInterface;

$router = new Router(
    webRoot: '/',
    httpHost: 'example.org', // From $_SERVER['HTTP_HOST']
    isHttps: true, // From $_SERVER['HTTPS']
    $dispatcher // A EventDispatcherInterface instance
);

// Define routes
$router->get(
    alias: 'home.index',
    urlPart: 'home',
    callable: [HomeController::class, 'index']
);

$router->get(
    alias: 'product.details',
    urlPart: 'details',
    callable: [ProductController::class, 'showDetails'],
    params: ['id']
);

$router->post(alias: 'submit', urlPart: 'submit', callable: [FormController::class, 'submit']);

// Generate a URL for a route
$url = $router->linkTo(['alias' => 'home']);
echo $url; // Outputs: https://example.org/home

// Generate a URL for a controller/method pair
$url = $router->linkTo(['@target' => [ProductController::class, 'showDetails'], 'id' => 123]);
echo $url; // Outputs: https://example.org/details/123

// Enter a context
$result = $router->enterContext(['alias' => 'product.details'], function(Router $router) {
    // Your code here
    return $router->linkToSelf(['id' => 123]);
});
echo $result; // Outputs: https://example.org/details/123

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-23