divinity76/phprouter

v1.3.0 2023-05-09 09:09 UTC

This package is not auto-updated.

Last update: 2024-09-24 15:22:23 UTC


README

php router API 受 https://github.com/bramus/router 启发,但此路由器不受 bramus/router#137 影响...这就是我制作这个路由器的原因

安装

路由器只是一个独立的 .php 文件,您可以将其复制粘贴。

另一个替代方案是使用 composer

composer require 'divinity76/phprouter'

使用方法

<?php
require_once(__DIR__ . '/vendor/autoload.php');
$router = new \Divinity76\Phprouter\Phprouter();
$router->get('/test', function() {
    echo 'test GET page';
});
$router->post("/test",function(){
    echo "test POST page";
});
$router->match("PATCH","/user/(\d+)/([^\\/])?",function(string $user_id, string $user_name_supplied){
    echo "you accessed user #".htmlentities($user_id). 
      ", you think his name is ".htmlentities($user_name)."...");
});
$router->set404(function(){
    echo "404 not found: ".htmlentities($_SERVER['REQUEST_URI']);
});
$router->run();