Thinkphp5 Route用法


域名路由:domain

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

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)

 

別名路由:alias

文件位置:application/route.php 

方法一:

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

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

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

 

方法二:

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'
    ],
    
];

 

 

路由綁定:get

代碼

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

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

注意:如果是偽靜態狀態下 要tp5a.com/模塊/方法(一定要帶模塊名) 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM