thinkphp5 註冊單個路由

設置路由

       第一步,先開啓路由模式(config.php)

'url_route_on'  =>  true,

       接下來,設置路由的文件、路徑:

               application/route.php 文件

       1、動態單個註冊

               靜態路由:

//引入系統的路由類
use think\Route;

//靜態路由
Route::rule('/','index/index/index'); //前臺首頁路由
Route::rule('test','index/index/test');//index(前臺)模塊index控制器test方法的路由

              帶參數的路由: 

//引入系統的路由類
use think\Route;

//調用test方法並傳參id,id必須傳值
Route::rule('test/:id','index/index/test');
//調用的url
url = 'http://localhost:8081/id/1';

//或者將參數先到Route::rule()的第二個參數
Route::rule('test/:id','index/index/test?id=1&num=3');

//調用test方法並傳參id和name,id必須傳值,num可選
Route::rule('test/:id/[:num]','index/index/test');
//調用的url
url = 'http://localhost:8081/2/1';

                動態路由: 

//引入系統的路由類
use think\Route;

//全動態路由(不建議使用)
Route::rule('/:id/:num','index/index/test');

//完全動態路由
Route::rule('test$','index/index/test');

            註冊批量路由:https://blog.csdn.net/beyond_1990/article/details/99545317

           設置路由的請求方式:https://blog.csdn.net/beyond_1990/article/details/99459472 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章