2017-09-13 81 views
0

如何在Zend Expressive 2中(使用HtmlResponse)更改或添加標題給響應?如何在Zend Expressive中更改或添加標題

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) 
    { 

    } 
} 

回答

0

這很容易。

你只需要讓委託來處理請求並得到響應返回,例如:

public function process(ServerRequestInterface $request, DelegateInterface $delegate) 
{ 
    $response = $delegate->process($request); 

    $now = new \DateTime(); 

    return $response->withHeader('Last-Modified', $now->format('c')); 

}