17

我们已经知道如何notFoundHandler在 Slim 3 中添加自定义 404:

$container['notFoundHandler'] = function ($c) {
    return function ($request, $response) use ($c) {
        return $c->view->render($response, 'pages/404.html.twig') 
            ->withStatus(404)
            ->withHeader('Content-Type', 'text/html');
    };
};

我想在我的一条路线中手动触发它。

在 Slim 2 中,我们能够做类似$app->notFound(). Slim 3 中的等价物是什么?

4

1 回答 1

26

您需要抛出 \Slim\Exception\NotFoundException 的新实例

throw new \Slim\Exception\NotFoundException($request, $response);
于 2016-04-26T16:27:30.527 回答