sw-fw-less
  • sw-fw-less
  • get started
    • Installation
    • Directory
    • Config
    • Quick Start
  • MVC
    • Router
    • Middleware
    • Request
    • Param Validator
    • Model
    • Response
  • Database
    • MySQL
    • Redis
    • Elasticsearch
  • Storage
    • General
    • File
    • Qiniu
    • Alioss
  • OTHER
    • Pagination
    • Helper
    • Error Handler
    • AMQP-0-9-1
    • Events
  • Deployment
    • Nginx
    • Docker
  • APPENDIX
    • Development Rules
Powered by GitBook
On this page
  • Config Example
  • Format
  • Match Rules
  • Router Middleware

Was this helpful?

  1. MVC

Router

Config Example

//Router
'router' => [
    'single' => [
        ['GET', '/ping', [\App\services\DemoService::class, 'ping']],
        ['GET', '/redis', [\App\services\DemoService::class, 'redis', [\App\middlewares\Cors::class]]],
        ['GET', '/mysql', [\App\services\DemoService::class, 'mysql']],
        ['GET', '/http', [\App\services\DemoService::class, 'http']],
        ['GET', '/es', [\App\services\DemoService::class, 'es']],
        ['GET', '/file', [\App\services\DemoService::class, 'file']],
        ['GET', '/qiniu', [\App\services\DemoService::class, 'qiniu']],
    ],
    'group' => [
        '/admin' => [
            ['GET', '/ping', [\App\services\DemoService::class, 'ping']],
        ],
    ],
],

Format

[{Request Method}, {Path}, [{Handler}, {Handle Method}, [{Middleware1}, {Middleware2}...]]]

[{Middleware1}, {Middleware2}...] is optional.

Match Rules

// Matches /user/42, but not /user/xyz
['GET', '/user/{id:\d+}', [\App\services\UserService::class, 'get']]

// Matches /user/foobar, but not /user/foo/bar
['GET', '/user/{name}', [\App\services\UserService::class, 'get']]

// Matches /user/foo/bar as well
['GET', '/user/{name:.+}', [\App\services\UserService::class, 'get']]

Router Middleware

The router supports multiple middlewares. The priority of router middleware is lower than the one of global middleware.

['GET', '/redis', [\App\services\DemoService::class, 'redis', [\App\middlewares\Cors::class]]]
PreviousQuick StartNextMiddleware

Last updated 6 years ago

Was this helpful?