svanvreckem/router

该包最新版本(1.0.5)没有提供许可证信息。

1.0.5 2020-09-07 08:13 UTC

This package is auto-updated.

Last update: 2024-09-08 02:51:03 UTC


README

安装

composer require svv/router:^1.0.5

目录结构

  • public
    • index.php
  • src
    • 控制器
      • HomeController.php

用法

  1. 第一个参数是要匹配的url,第二个参数是您类的命名空间
  2. 第一个参数是路径,第二个是回调函数,第三个是名称
    • 如果名称为null,则路由的名称将是回调函数的名称
  3. 您可以使用with方法更改类型提示的正则表达式
$router = new Svv\Router($_SERVER["REQUEST_URI"], "App\\");

$router->get("/home", "Home#index");
$router->post("/home", "Home#index");

$router->get("/post/{slug}-{id}", "Post#show", "post.show")
       ->with("id", "[0-9]+")
       ->with("slug", "[a-zA-Z0-9\-]+");

$router->run();