【发布时间】:2015-02-04 22:01:56
【问题描述】:
在应用程序登录中,我有以下代码在记录错误时抛出 ...HttpException:
// common/models/LoginForm.php which is called from the backend SiteController actionLogin method as $model = new LoginForm();
public function loginAdmin()
{
//die($this->getUser()->getRoleValue()."hhh");
if ($this->getUser()->getRoleValue() >= ValueHelpers::getRoleValue('Admin') && $this->getUser()->getStatusValue() == ValueHelpers::getStatusValue('Active')){
if ($this->validate()){
return \Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600*24*30:0);
}
else{
throw new \yii\web\NotFoundHttpException('Incorrect Password or Username.');
}
}
else{
throw new \yii\web\ForbiddenHttpException('Insufficient privileges to access this area.');
}
}
它工作正常,但我想自定义使用NotFoundHttpException 和ForbiddenHttpException 呈现的页面。我试图搜索Yii2 api 以查找任何可能在对象构造中定义视图的参数,但我找不到。那么,有没有办法自定义异常的视图呢?
【问题讨论】:
标签: php yii2 yii2-advanced-app