Blogger Information
Blog 14
fans 0
comment 0
visits 16141
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
路由分组技术
依然很m丶的博客
Original
1178 people have browsed it

路由分组技术:

在index/controller新建控制器User.php

<?phpnamespace app\index\controller;  //命名空间
class User{   
 public function demo1($id)   
 {       
   return '我是index模块User控制器的demo1方法,$id='.$id;  
 }   
 public function demo2($name)   
 {      
   return '我是index模块User控制器的demo2方法,$name='.$name;   
 }   
  public function demo3($isOk)   
 {     
   return '我是index模块User控制器的demo3方法,$isOk='.$isOk;  
    }
}

创建Route规则

think\Route::group('demo',//分组名称
    [
        ':id'  =>'demo1',//路由规则
        ':name'=>'demo2',
        ':isOk'=>'demo3'
    ], [
         'method'=>'get',        //路由参数
         'prefix'=>'index/user/'
    ], [
        'id'  =>'\d{2}',         //变量规则
        'name'=>'[a-zA-Z]+',
        'isOk'=>'0|1'
    ]
);

浏览器访问:域名/demo/id          例如  tp5.com/20

                    域名/demo/name    例如  tp5.com/php

                    域名/demo/idOk      例如  tp5.com/1 


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post