3.3 请求
请求对象(Request)
是完全基于 PSR-7 标准实现的,由 hyperf/http-message 组件提供实现支持。
注意 PSR-7 标准为请求(Request)
进行了immutable 机制
的设计,所有以with
开头的方法的返回值都是一个新对象,不会修改原对象的值
1. 引入请求的对象
<?php
namespace AppController;
use HyperfDiAnnotationInject;
use HyperfHttpServerContractRequestInterface;
use HyperfHttpServerContractResponseInterface;
use PsrContainerContainerInterface;
abstract class AbstractController
{
/**
* @Inject
* @var HyperfHttpServerContractRequestInterface
*/
protected $request;
}
2. 获取的方式
<?php
# 获取所有参数
$this->request->all()
# 获取指定的参数
$this->request->input('name', '');
# 获取url上的参数
$this->request->query('name', '');
具体更多的获取方式可通过查看hyperf官方文档或psr7中的内容