首页 > 代码库 > Thinkphp5笔记八:路由别名Route

Thinkphp5笔记八:路由别名Route

主要作用:隐藏自己的真实路由名称

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