最新消息: 新版网站上线了!!!

yii2 url路由

'new/<page:\d+>' => 'site/new',
'new' => 'site/new',

通过规则定默认值。

[
    'pattern' => '/new/<page:\d+>',
    'route' => 'site/new',
    'defaults' => [
        'page' => 1
    ],
],

有正则在的在上面显示 没有正则的在下面显 如

'new/<page:\d+>' => 'site/new',
'new' => 'site/new',

更多例子

'jobs/<category:\w+>,<subcategory:\w+>/<state:\w+>,<city:\w+>/<page:\d>' => 'site/jobs',
'jobs/<category:\w+>,<subcategory:\w+>/<state:\w+>/<page:\d>' => 'site/jobs',
'jobs/<category:\w+>,<subcategory:\w+>/<page:\d>' => 'site/jobs',
'jobs/<category:\w+>/<state:\w+>,<city:\w+>/<page:\d>' => 'site/jobs',
'jobs/<category:\w+>/<state:\w+>/<page:\d>' => 'site/jobs',
'jobs/<category:\w+>/<page:\d>' => 'site/jobs',
'jobs/<category:\w+>,<subcategory:\w+>/<state:\w+>,<city:\w+>' => 'site/jobs',
'jobs/<category:\w+>,<subcategory:\w+>/<state:\w+>' => 'site/jobs',
'jobs/<category:\w+>,<subcategory:\w+>' => 'site/jobs',
'jobs/<category:\w+>/<state:\w+>,<city:\w+>' => 'site/jobs',
'jobs/<category:\w+>/<state:\w+>' => 'site/jobs',
'jobs/<category:\w+>' => 'site/jobs',
'jobs' => 'site/jobs',

转载请注明:谷谷点程序 » yii2 url路由