zoukankan      html  css  js  c++  java
  • 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 "路由群组";
        });
    });
  • 相关阅读:
    插入排序
    选择排序
    P1338 末日的传说 逆序数对
    P1582倒水 位运算
    P2158 [SDOI2008] (欧拉函数
    HDU 6274 二分+预处理(CCPC K题
    P1219 N皇后
    [USACO1.5] 回文质数
    Codeforces #123D: 后缀数组+单调栈
    单调栈 单调队列
  • 原文地址:https://www.cnblogs.com/huqi96/p/15677637.html
Copyright © 2011-2022 走看看