本文整理汇总了PHP中HttpException::getCode方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpException::getCode方法的具体用法?PHP HttpException::getCode怎么用?PHP HttpException::getCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpException
的用法示例。
在下文中一共展示了HttpException::getCode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run()
{
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 = $this->defaultName ?: Yii::t('yii', 'Error');
}
if ($code) {
$name .= " (#{$code})";
}
if ($exception instanceof UserException) {
$message = $exception->getMessage();
} else {
$message = $this->defaultMessage ?: Yii::t('yii', 'An internal server error occurred.');
}
if (Yii::$app->getRequest()->getIsAjax()) {
return "{$name}: {$message}";
} else {
return $this->controller->render($this->view ?: $this->id, ['name' => $name, 'message' => $message, 'exception' => $exception]);
}
}
示例2: convertExceptionToArray
/**
* Converts an exception into an array.
* @param \Exception $exception the exception being converted
* @return array the array representation of the exception.
*/
protected function convertExceptionToArray($exception)
{
if (!YII_DEBUG && !$exception instanceof UserException && !$exception instanceof HttpException) {
$exception = new HttpException(500, 'There was an error at the server.');
}
$array = ['code' => $exception->getCode(), 'message' => $exception->getMessage()];
if ($exception instanceof LBUserException) {
$array['data'] = $exception->getErrors();
}
return $array;
}
示例3: defaultHttpRender
/**
* render the HttpException in the general case
*
* @param HttpException $error an instance of HttpException
* @return void
*/
protected function defaultHttpRender(HttpException $error)
{
$url = $this->controller->request->here();
$code = $error->getCode() >= 400 && $error->getCode() < 506 ? $error->getCode() : 500;
$this->controller->response->statusCode($code);
$this->controller->set(array('code' => $code, 'name' => h(get_class($error)), 'message' => h($error->getMessage()), 'url' => h($url), 'error' => $error, '_serialize' => array('code', 'name', 'message', 'url')));
$template = $code >= 400 && $code < 500 ? 'error400' : 'error500';
$this->_outputMessage($template);
}