Skip to content
axios edited this page Oct 13, 2020 · 2 revisions

Configuration

The path to the configuration file of Route is Path::config()/routes.php.

  • path
    • the path info of request, must be start with '/'
    • use {:<arg-name>} to set param in path
    • use ** to ingore string before next '/'
    • ignore all strings from ***
  • method
    • the method of request
  • handler
    • combine with <module>/<controller>/<action>, index/index/index for example
  • intro
    • the information of route

Exmpale

<?php

# routes.php

return [
    [
        'path'    => '/',                 // request path info
        'method'  => 'get|post',          // request method
        'handler' => 'index/index/index', // <module>/<controller>/<action>
        'intro'   => 'homepage',          // optional, intro of route
    ],
    [
        'path'    => '/test/{:id}/{:title}/foo/{:bar}', // with params
        'method'  => 'all',                             // match all request method
        'handler' => 'index/index/index',
        'intro'   => 'has param',
    ],
    [
        'path'    => '/has/**/text/{:name}',           // ** : ingore string before next '/'
        'method'  => 'post',
        'handler' => 'index/index/index',
        'intro'   => 'ignore part of path',
    ],
    [
        'path'    => '/admin/***', // *** : ignore string
        'method'  => 'all',
        'handler' => 'index/index/illegal',
        'intro'   => 'default route rule',
    ],
    [
        'path'    => '/***', // *** : ignore string
        'method'  => 'all',
        'handler' => 'index/index/notFound',
        'intro'   => 'the default route rule when none of the above rules are matched',
    ]
];
Clone this wiki locally