php路由

Route::get("/hello",function(){
    return "hello world";
});
//匹配所有请求
Route::any("/hello1",function(){
    return "hello world1";
});
//匹配两种请求方式
Route::match(['post','get'],"hello2",function (){
    return "hello world2";
});
 /*
 * 1.php中地址栏传参用{参数}:表示为必填 ,{参数?}表示为选填
 * 2.方法中参数形参声明用$变量名称
 *3.使用的时候同样是$value,变量和字符串拼接用.
 */
Route::any("/param/{value}",function ($value){
    return $value."测试";
});
// 可选参数,形参变量不传时一定要赋值
Route::any("/param1/{value?}",function ($value = ''){
    return $value."测试1";
});

//路由地址通过?id=参数 。接受参数时用$_GET["id"]
Route::any("/param2",function (){
   return "问号传参".$_GET["id"];
});

//路由别名
Route::any("/param3",function (){
    return "问号传参".$_GET["id"];
})->name("路由名称");

//路由群组,像spring mvc中的controller的公共的@RequestMapping
Route::group(["prefix"=>"admin"],function (){
    Route::get("/test",function () {
        return "路由群组";
    });
});

 

posted @ 2021-12-11 23:11  动力起点  阅读(504)  评论(0编辑  收藏  举报