【php】hyperf笔记-路由注解

1 什么是路由注解?

 路由注解是写在类或方法上的,用于的绑定方法和UR并配置请求方式。

2 路由前缀

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php

declare(strict_types=1);

namespace App\Controller;

...
use Hyperf\HttpServer\Annotation\AutoController;

/**
* @AutoController(prefix="/users")
*
*/
class IndexController extends AbstractController
{
public function index()
{
$user = $this->request->input('user', 'Hyperf');
$method = $this->request->getMethod();

return [
'method' => $method,
'message' => "Hello {$user}.",
];
}
...

GET请求index方法的链接为/users

路由如果要使用注解的方式,在不配置前缀的前提下, 则心命名空间加类名为URI前缀.

坚持原创技术分享,您的支持将鼓励我继续创作!
0%