Thinkphp的自定义路由(route.php)


废话:因为thinkphp的默认路由会导致URL特别长,从而会影响搜索引擎优化。所以就衍生了自定义路由,尽量将URL缩短。

这是默认的路由文件:

 1 <?php
 2 return [
 3     '__pattern__' => [
 4         'name' => '\w+',
 5     ],
 6     '[hello]'     => [
 7         ':id'   => ['index/hello', ['method' => 'get'], ['id' => '\d+']],
 8         ':name' => ['index/hello', ['method' => 'post']],
 9     ],
10 
11 ];

hello可以很明显的跟/index/hello是对应的,也就是说hello其实就是index模块下的hello方法。但是要满足这个调用链,就必须要有id和name这个参数(加[]变成可选),然后id参数的属性要为get且满足\d+这个正则,name参数的的属性要为post才调用index/hello

如下所示:

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM