ale*_*exw 16 php httpresponse slim slim-3
我们已经知道如何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');
};
};
Run Code Online (Sandbox Code Playgroud)
我想在我的一条路线中手动触发.
在Slim 2中,我们能够做类似的事情$app->notFound()
.Slim 3中的等价物是什么?
Ben*_*rne 24
您需要抛出\ Slim\Exception\NotFoundException的新实例
throw new \Slim\Exception\NotFoundException($request, $response);
Run Code Online (Sandbox Code Playgroud)