PHP code example of qnnp / webman-route

1. Go to this page and download the library: Download qnnp/webman-route 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/ */

    

qnnp / webman-route example snippets



# file:/app/api/controller/index.php

namespace app\api\controller

use Qnnp\WebmanRoute\Module\Result;use support\Request;
use support\Response;
use Throwable;
use Qnnp\WebmanRoute\Attributes\Route;

class Index {
  #[Route(
    './',                               // 路由 /api/test
    middleware: [RequireLogin::class],  // 加载中间件
    get: [                              // GET 方法各项参数
      'orderBy' => [
        get::schema => [
          schema::enum => ['status', 'last_active_time', 'created_at']
        ]
      ],
      'order'   => [
        get::schema  => [
          schema::enum => ['asc', 'desc']
        ],
        get::example => 'desc',
      ],
      'page'    => [
        get::example => 1,
        get::schema  => ['type' => 'integer']
      ],
      'limit'   => [
        get::example => 10,
        get::schema  => [
          schema::type => 'integer'
        ]
      ],
    ],
    tags: ['测试分组'],                  // 路由分组
    summary: '测试路由"/api/test"',      // 路由描述
  )]
  public function test(Request $request):Response {
    return Result::json('success');
  }
}