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