美文网首页
tp5路由配置笔记!

tp5路由配置笔记!

作者: DragonersLi | 来源:发表于2020-03-20 11:22 被阅读0次
    thinkphp5.0只有路由,没有中间件功能。要么升级框架。要么使用其它方式替代,比如控制器加入前置方法然后在基类里判断是否有访问权限等...
    5.0的路由route.php配置:
    // 注意:要先application/config.php 开启 域名部署(url_domain_deploy => true)
    // true开启混合模式路由,false关闭路由   'url_route_on' => true,
    // 强制路由模式 'url_route_must'=>  true,
    // 路由配置文件(默认route,支持配置多个) 'route_config_file'      => ['route','route_api'],
    Route::domain('m','app');//绑定前端模块
    Route::domain('admin.xxx.com','admin');//绑定后端模块
    
    Route::group('api',[
        # api/index 对应api/Test/index路径
        'index'   => ['api/Test/index', ['method' => 'get']],
    ]);
     
    /*APP路由*/ 
    Route::domain('m',function(){
        
        //资源路由
        Route::resource('testabcd','app/test');//别名(别名,模块/控制器)
         
        //快捷路由(除了index方法,其它方法前面都以get为前缀命名)
        Route::controller('app/test','app/test');//控制器路由(模块/控制器)
     
            
            //路由分组
            Route::group('testabc',function(){ 
                
                //常用路由(get,post,any,put,delete...)
                Route::get('', 'test/sendmsg');//别名 (控制器/方法)
                Route::alias('d','app/test/sendmsg');//别名路由(别名,模块/控制器/方法)
                Route::rule('q','app/test/sendmsg');//别名路由(别名,模块/控制器/方法)
         
                Route::any('s','app/test/sendmsg',['callback'=>'checkRoute']);
                
                Route::group(['middleware'=>'AccessMiddleware'],function(){
                    
                });
    
    
            }); 
    });
    
     
    

    相关文章

      网友评论

          本文标题:tp5路由配置笔记!

          本文链接:https://www.haomeiwen.com/subject/ixjjshtx.html