为了测试,我在模型中添加了这段代码,同时设置 debug = true 和 false。
if($packagedays < 1)
{
throw new \yii\base\Exception( "package days cannot be less than 1" );
}
现在当 Yii debug 为 true 时:我得到了
异常 – yii\base\Exception 包裹天数不能小于1
但是当我将调试设置为 false 时
我正进入(状态
异常(exception)
发生内部服务器错误。
Web 服务器处理您的请求时发生上述错误。
我想要的是替换发生内部服务器错误。
和
当
debug=false
我在这里缺少什么?
谢谢。
最佳答案
您应该简单地抛出一个UserException
:
UserException is the base class for exceptions that are meant to be shown to end users.
了解更多:http://www.yiiframework.com/doc-2.0/yii-base-userexception.html
关于php - yii2:抛出新异常的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28746429/