废话:因为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

如下所示:

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

相关文章:

  • 2022-02-13
  • 2021-06-22
  • 2022-02-26
  • 2021-05-11
  • 2022-12-23
  • 2021-06-19
  • 2021-10-10
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-23
  • 2022-12-23
  • 2021-10-20
  • 2021-08-12
  • 2021-07-20
  • 2022-01-07
相关资源
相似解决方案