私人领地

Thinkphp5笔记八:路由别名Route

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

application/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

 

注释:别名 => ‘模型/控制器’ ( 别名等于模块+控制器)

 

posted @ 2017-05-06 00:07  狂奔的蜗牛Snails  阅读(2909)  评论(0编辑  收藏  举报