当前位置: 首页>>代码示例>>PHP>>正文


PHP HttpException::getCode方法代码示例

本文整理汇总了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]);
     }
 }
开发者ID:rubedkhan2149,项目名称:2149,代码行数:30,代码来源:ErrorAction.php

示例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;
 }
开发者ID:anihy,项目名称:yii2-account,代码行数:16,代码来源:LBErrorHandler.php

示例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);
 }
开发者ID:loadsys,项目名称:cakephp-serializers-errors,代码行数:15,代码来源:SerializerExceptionRenderer.php


注:本文中的HttpException::getCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。