首页 > 其他 > 详细

TP5总结路由

时间:2019-03-09 16:48:32      阅读:148      评论:0      收藏:0      [点我收藏+]

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+‘]],
];

TP5总结路由

原文:https://www.cnblogs.com/wjr2018/p/10501806.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!