在 symfony 中,当我在数据库中找不到元素时,如何从 Controller 重定向到自定义 404 错误页面?
例如:
if ( empty($db_result) ) {
/* DO REDIRECT */
} else {
return $this->render('default/correct.html.twig');
}
最佳答案
试试这个方法:
if ( is_null($db_result) ) {
throw $this->createNotFoundException();
} else {
return $this->render('default/correct.html.twig');
}
关于php - Symfony,重定向到(或呈现)带有 404 状态返回码的 404 自定义错误页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46920964/