Final Class Yiisoft\Yii\Http\Handler\NotFoundHandler
| Inheritance | Yiisoft\Yii\Http\Handler\NotFoundHandler |
|---|---|
| Implements | Psr\Http\Server\RequestHandlerInterface |
NotFoundHandler is used as a fallback handler by default {@see \Yiisoft\Yii\Http\Application}.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Yii\Http\Handler\NotFoundHandler | |
| handle() | Handles a request and produces a response. | Yiisoft\Yii\Http\Handler\NotFoundHandler |
Method Details
| public mixed __construct ( \Psr\Http\Message\ResponseFactoryInterface $responseFactory ) | ||
| $responseFactory | \Psr\Http\Message\ResponseFactoryInterface | |
public function __construct(
private readonly ResponseFactoryInterface $responseFactory,
) {
}
Handles a request and produces a response.
May call other collaborating code to generate the response.
| public \Psr\Http\Message\ResponseInterface handle ( \Psr\Http\Message\ServerRequestInterface $request ) | ||
| $request | \Psr\Http\Message\ServerRequestInterface | |
public function handle(ServerRequestInterface $request): ResponseInterface
{
$path = $request->getUri()->getPath();
$response = $this->responseFactory->createResponse(Status::NOT_FOUND);
$response->getBody()->write("We were unable to find the page \"$path\".");
return $response;
}
Signup or Login in order to comment.