zoukankan      html  css  js  c++  java
  • 路由、控制器笔记

    1 基础路由写法

    Route::get('/index',function (){
        return 'hello word';
    });
    //http://127.0.0.1:8000/index

     2、match 接收指定的提交方式

    Route::match(['get','post'],'match',function (){
        return 'match';
    });

    3 、路由中传递参数

    Route::get('index/{id}',function ($id){
        return 'index'.$id;
    });
    //http://127.0.0.1:8000/index/abc123 返回indexabc123

     4、控制其中传参

    Controllers/TestController.php

    public function read($id){
    
            return 'id:'.$id;
    
        }
    Route::get('/test/read/{id}','TestController@read');
    // http://127.0.0.1:8000/test/read/1 返回1
    Route::get('/test/read/{id}','TestController@read')->where('id','[0-9]+');  //限定传递参数   使用正则表达式
    //  http://127.0.0.1:8000/test/read/1 返回1 只能是数字

     也可以是数组

    Route::get('/test/read/{id}','TestController@read')->where(['id'=>'[0-9]+']);

     路由全局限定

    app\Providers\RouteServiceProvider.php文件中

     public function boot()
        {
            Route::pattern('id','[0-9]+');
            //
    
            parent::boot();
        }

    限定解除  

    where(['id'=>'.*']);

    5、路由重定向

    Route::redirect('index','test',301);

    6 、视图路由

    Route::view('news','news');

    第一个参数为url  第二个参数为 模板名称

    第二中方法

    Route::get('shop',function (){
        return view('shop');
    });

     7、获取url

    public function url(){
            $url=Route('shop');
            return $url;
        }
    也可以传递参数
    $url=Route('shop',['id'=>'10']);

     8  路由分组

    Route::group(['prefix'=>'admin'],function (){
        Route::get('index','AdminController/index');
    
    });
  • 相关阅读:
    MFC框架程序实现十一
    MFC框架程序实现八
    MFC框架程序实现十二
    在Visual C++中如何利用UDL文件来建立ADO连接
    OnePage收集 HA
    微博跳转的url HA
    淘宝iosapp调用规范 HA
    Excel操作相关 HA
    C#GDI+编程基础 HA
    html5deoms HA
  • 原文地址:https://www.cnblogs.com/linzenews/p/12727275.html
Copyright © 2011-2022 走看看