類別 yii\web\HttpException
HttpException 代表終端使用者不當請求所造成的例外。
HttpException 可以透過其 $statusCode 屬性值來區分,該屬性值保留標準 HTTP 狀態碼 (例如 404、500)。錯誤處理器可以使用此狀態碼來決定如何格式化錯誤頁面。
拋出像以下範例中的 HttpException 將會顯示 404 頁面。
if ($item === null) { // item does not exist
throw new \yii\web\HttpException(404, 'The requested Item could not be found.');
}
屬性詳細資訊
方法詳細資訊
建構子。
public void __construct ( $status, $message = null, $code = 0, $previous = null ) | ||
$status | 整數 |
HTTP 狀態碼,例如 404、500 等。 |
$message | string|null |
錯誤訊息 |
$code | 整數 |
錯誤代碼 |
$previous | Throwable|null |
用於例外鏈結的前一個例外。 |
public function __construct($status, $message = null, $code = 0, $previous = null)
{
$this->statusCode = $status;
parent::__construct((string)$message, $code, $previous);
}
請註冊 或 登入 以進行留言。