廢話:因為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
如下所示: