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 "路由群组";
        });
    });
  • 相关阅读:
    常见HTTP状态码
    Spring MVC 原理小结
    RESTful API
    java:IO流学习小结
    理解 Statement 和 PreparedStatement
    Hibernate缓存原理与策略
    APP运营
    网站常见术语
    php常见术语
    运维------术语名词
  • 原文地址:https://www.cnblogs.com/huqi96/p/15677637.html
Copyright © 2011-2022 走看看