0 フォロワー

クラス yii\web\HttpException

全てのクラス All Classes | プロパティ Properties | メソッド Methods
継承yii\web\HttpException » yii\base\UserException » yii\base\Exception » Exception
サブクラスyii\web\BadRequestHttpException, yii\web\ConflictHttpException, yii\web\ForbiddenHttpException, yii\web\GoneHttpException, yii\web\MethodNotAllowedHttpException, yii\web\NotAcceptableHttpException, yii\web\NotFoundHttpException, yii\web\RangeNotSatisfiableHttpException, yii\web\ServerErrorHttpException, yii\web\TooManyRequestsHttpException, yii\web\UnauthorizedHttpException, yii\web\UnprocessableEntityHttpException, yii\web\UnsupportedMediaTypeHttpException
利用可能バージョン2.0
ソースコード https://github.com/yiisoft/yii2/blob/master/framework/web/HttpException.php

HttpException は、エンドユーザーによる不正なリクエストによって発生する例外を表します。

HttpException は、標準的なHTTPステータスコード(例:404、500)を保持する $statusCode プロパティの値によって区別できます。エラーハンドラーは、このステータスコードを使用して、エラーページのフォーマット方法を決定できます。

次の例のように HttpException をスローすると、404ページが表示されます。

if ($item === null) { // item does not exist
    throw new \yii\web\HttpException(404, 'The requested Item could not be found.');
}

公開プロパティ

継承されたプロパティを非表示

プロパティ 説明 定義元
$statusCode 整数 HTTPステータスコード(例:403、404、500など) yii\web\HttpException

公開メソッド

継承されたメソッドを非表示

メソッド 説明 定義元
__construct() コンストラクタ。 yii\web\HttpException
getName() yii\web\HttpException

プロパティの詳細

継承されたプロパティを非表示

$statusCode 公開プロパティ

HTTPステータスコード(例:403、404、500など)

public integer $statusCode = null

メソッドの詳細

継承されたメソッドを非表示

__construct() 公開メソッド

コンストラクタ。

public void __construct ($status, $message = null, $code = 0, $previous = null)
$status 整数

HTTPステータスコード(例:404、500など)

$message 文字列|null

エラーメッセージ

$code 整数

エラーコード

$previous Throwable|null

例外チェーンに使用された以前の例外。

                public function __construct($status, $message = null, $code = 0, $previous = null)
{
    $this->statusCode = $status;
    parent::__construct((string)$message, $code, $previous);
}

            
getName() publicメソッド

public string getName ( )
戻り値 string

この例外のユーザーフレンドリーな名前

                public function getName()
{
    if (isset(Response::$httpStatuses[$this->statusCode])) {
        return Response::$httpStatuses[$this->statusCode];
    }
    return 'Error';
}