Thinkphp5筆記八:路由別名Route
阿新 • • 發佈:2017-05-06
d+ oca 控制 edi code dmi 控制器 color local
主要作用:隱藏自己的真實路由名稱
Route.php
使用方法一:
<?php use think\Route; Route::alias(‘home‘,‘index/index‘); Route::alias(‘admin‘,‘admin/index‘);
方法二:
<?php return [ ‘__pattern__‘ => [ ‘name‘ => ‘\w+‘, ], ‘[hello]‘ => [ ‘:id‘ => [‘index/hello‘, [‘method‘ => ‘get‘], [‘id‘ => ‘\d+‘]], ‘:name‘ => [‘index/hello‘, [‘method‘ => ‘post‘]], ], ‘__alias__‘ => [ ‘home‘ => ‘index/index‘, ‘admin‘=> ‘admin/index‘ ], ];
http://localhost/thinkphp/index.php/home/test 同等與http://localhost/thinkphp/index.php/index/index/test
http://localhost/thinkphp/index.php/admin/edit/ 同等與http://localhost/thinkphp/index.php/admin/index/edit
註釋:別名 => ‘模型/控制器’ ( 別名等於模塊+控制器)
Thinkphp5筆記八:路由別名Route