0 追蹤者

類別 yii\web\UnauthorizedHttpException

繼承關係yii\web\UnauthorizedHttpException » yii\web\HttpException » yii\base\UserException » yii\base\Exception » Exception
自版本起可用2.0
原始碼 https://github.com/yiisoft/yii2/blob/master/framework/web/UnauthorizedHttpException.php

UnauthorizedHttpException 代表「未授權」HTTP 例外,狀態碼為 401。

使用此例外來指示用戶端需要透過 WWW-Authenticate 標頭進行驗證,才能執行請求的動作。

如果用戶端已經過驗證,但僅僅是不允許執行該動作,請考慮改用 403 yii\web\ForbiddenHttpException 或 404 yii\web\NotFoundHttpException

公開屬性

隱藏繼承的屬性

屬性 類型 描述 定義於
$statusCode integer HTTP 狀態碼,例如 403、404、500 等。 yii\web\HttpException

方法詳細資訊

隱藏繼承的方法

__construct() 公開方法

建構子。

public void __construct ( $message null, $code 0, $previous null )
$message string|null

錯誤訊息

$code integer

錯誤代碼

$previous Throwable|null

用於例外鏈結的前一個例外。

                public function __construct($message = null, $code = 0, $previous = null)
{
    parent::__construct(401, $message, $code, $previous);
}

            
getName() public method
public string getName ( )
回傳 string

此例外狀況的使用者友善名稱

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