Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我看到,在大多数 Symfony 2 示例中,当记录不存在时,Symfony 2 会抛出异常。我发现这种方法对最终用户不友好。为什么有人更喜欢抛出异常而不是在 flashbag 中添加一些错误消息?
在示例中,它通常会引发异常
throw $this->createNotFoundException('Message');
它将用户重定向到 404 错误页面。
在 CMS 中,如果未找到记录,您可能希望向用户显示 404 页面,而不是向闪存包添加错误并将它们重定向到主页。
我想这取决于您的应用程序需求以及您希望如何处理它。