tp5路由规则

1.路由定义在application/route.php里面定义,可以用Route类来定义。

$route = new \think\Route();
$route->get('名称','模块/控制器/方法');//get请求
$route->post('名称','模块/控制器/方法');//post请求
$route->rule('名称','模块/控制器/方法');//get请求

可以数组定义

return[
    'name/:参数'=>'模块/控制器/方法',
    'name/[:可选参数]'=>'模块/控制器/方法',
];
return [
    'blog/:year/:month' => ['blog/archive', ['method' => 'get'], ['year' => '\d{4}', 'month' => '\d{2}']],
    'blog/:id'          => ['blog/get', ['method' => 'get'], ['id' => '\d+']],
    'blog/:name'        => ['blog/read', ['method' => 'get'], ['name' => '\w+']],
];

转自https://blog.csdn.net/fly_horses/article/details/79459706

猜你喜欢

转载自blog.csdn.net/qq_42572322/article/details/81510536