yii\web\HttpException::getName PHP Метод

getName() публичный Метод

public getName ( ) : string
Результат string the user-friendly name of this exception
    public function getName()
    {
        if (isset(Response::$httpStatuses[$this->statusCode])) {
            return Response::$httpStatuses[$this->statusCode];
        } else {
            return 'Error';
        }
    }

Usage Example

Пример #1
39
 /**
  * Redefine error message for own styling
  *
  * @return string
  */
 public function actionError()
 {
     if (($exception = Yii::$app->getErrorHandler()->exception) === null) {
         // action has been invoked not from error handler, but by direct route, so we display '404 Not Found'
         $exception = new HttpException(404, Yii::t('yii', 'Page not found'));
     }
     if ($exception instanceof HttpException) {
         $code = $exception->statusCode;
     } else {
         $code = $exception->getCode();
     }
     if ($exception instanceof Exception) {
         $name = $exception->getName();
     } else {
         $name = Yii::t('yii', 'Error');
     }
     if ($code) {
         $name .= " (#{$code})";
     }
     if ($exception instanceof UserException) {
         $message = $exception->getMessage();
     } else {
         $message = Yii::t('yii', 'An internal server error occurred');
     }
     if (Yii::$app->getRequest()->getIsAjax()) {
         return "{$name}: {$message}";
     } else {
         $this->layout = 'main';
         return $this->render('error', ['code' => $code, 'name' => $name, 'message' => $message, 'exception' => $exception]);
     }
 }
All Usage Examples Of yii\web\HttpException::getName