gpt4 book ai didi

php - Symfony,重定向到(或呈现)带有 404 状态返回码的 404 自定义错误页面

转载 作者:行者123 更新时间:2023-12-01 22:12:46 24 4
gpt4 key购买 nike

在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com