Thinkphp5 Route用法

域名路由:domainphp

1.application/router.php 文件位置,吧一下代碼放進去就能夠了app

use think\Route;
Route::domain('app.tp5a.com','app');   // 1.綁定到模塊app
#Route::domain('app.tp5a.com','app/category'); //2.綁定到控制器category
#Route::domain('app.tp5a.com','app/category/test');   //3.綁定到方法test
把域名app.tp5a.com  綁定到模塊 app模塊

注意:要先application/config.php 開啓 域名部署(url_domain_deploy => true)

 

別名路由:aliasdom

文件位置:application/route.php post

方法一:url

use think\Route;
Route::alias('test','index/index/test');

當訪問xxx.com  會跳轉到index/index/testspa

訪問地址:http://tp5a.com/index.php/test   等同於  http://tp5a.com/index.php/index/index/testcode

 

方法二:router

return [
    '__pattern__' => [
        'name' => '\w+',
    ],
    '[hello]'     => [
        ':id'   => ['index/hello', ['method' => 'get'], ['id' => '\d+']],
        ':name' => ['index/hello', ['method' => 'post']],
    ],
    '__alias__' =>  [
        'h'  =>  'index/hello',
        'test'=> 'index/index/test'
    ],
    
];

 

 

路由綁定:getblog

代碼路由

Route::get('test','index/index/test');

訪問  http://tp5a.com/index/test  和    http://tp5a.com/index.php/test

注意:若是是僞靜態狀態下 要tp5a.com/模塊/方法(必定要帶模塊名) 

相關文章
相關標籤/搜索