PHP code example of hyperf-ext / http-server-router

1. Go to this page and download the library: Download hyperf-ext/http-server-router library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hyperf-ext / http-server-router example snippets


use Hyperf\HttpServer\Router\Router;

Router::addGroup('/users/{id}', function () {
    Router::get('/comments', 'App\Controller\IndexController@index', ['name' => 'comments.index']); // 该路由名称将被组合为 `users.comments.index`
}, ['name' => 'users.']);

use Hyperf\HttpServer\Router\Router;

/** @var \HyperfExt\HttpServer\Router\Route $route */
$route = Router::getRoute('users.comments.index');

use Hyperf\HttpServer\Router\Router;

/** @var \HyperfExt\HttpServer\Router\Route $route */
$route = Router::getCurrentRoute();

/**
 * @var \HyperfExt\HttpServer\Router\Route $route
 * @var \Hyperf\HttpMessage\Uri\Uri $uri
 */
$uri = $route->createUri([
    'id' => 123,
    'page_num' => 2,
    'page_size' => 20,
]);
$link = (string) $uri; // 结果为 `/users/123/comments?page_num=2&page_size=20`