如何在Zend Expressive中更改或添加标题

问题描述 投票:1回答:2

如何在Zend Expressive 2中使用HtmlResponse更改或添加标题?

class NotModifiedMiddleware implements ServerMiddlewareInterface
{

    /**
     * Process an incoming server request and return a response, optionally delegating
     * to the next middleware component to create the response.
     *
     * @param ServerRequestInterface $request
     * @param DelegateInterface $delegate
     *
     * @return ResponseInterface
     */
    public function process(ServerRequestInterface $request, DelegateInterface $delegate)
    {

    }
}
php request response zend-framework3 zend-expressive
2个回答
1
投票

qazxsw poi,作为第三个参数接收在初始化时使用的标头数组。

举个例子:

HtmlResponse

1
投票

这很简单。

您只需要让委托处理请求并获得响应,例如:

return new HtmlResponse($data, 200, ['Content-Type' => 'application/x-yaml']);
© www.soinside.com 2019 - 2024. All rights reserved.