hyperf初体验路由

1.闭包定义路由

Router::get('/hello-hyperf',function (){
    return 'Hello Hyperf';
});

hyperf路由_ecmascript

2.标准路由三种写法

Router::get('/hello-hyperf1','App\Controller\TestController::index');
Router::get('/hello-hyperf2','App\Controller\TestController@index2');
Router::get('/hello-hyperf3',[App\Controller\TestController::class,'index3']);

在Controller目录下新建TestController控制器

<?php
namespace App\Controller;


class TestController extends AbstractController
{

    public function index()
    {
        return '123';
    }

    public function index2()
    {
        return '456';
    }

    public function index3()
    {
        return '789';
    }


}

hyperf路由_App_02


hyperf路由_App_03


hyperf路由_ecmascript_04

3.路由组

//路由组
Router::addGroup('/goods/',function(){
    Router::get('index',[App\Controller\GoodsController::class,'index']);
    Router::post('store',[App\Controller\GoodsController::class,'store']);
});

在Controller目录下新建GoodsController控制器

<?php
namespace App\Controller;


class GoodsController extends AbstractController
{


    public function index()
    {
        return 'goods';
    }


    public function store()
    {
        return 'store-post';
    }


}

hyperf路由_php_05


希望大佬们指正