Commit f72c451c by Qiang Xue

Display debug toolbar on error pages.

parent 1398de3f
......@@ -475,6 +475,8 @@ abstract class Application extends Module
*/
public function handleFatalError()
{
unset($this->_memoryReserve);
// load ErrorException manually here because autoloading them will not work
// when error occurs while autoloading a class
if (!class_exists('\\yii\\base\\Exception', false)) {
......@@ -487,7 +489,6 @@ abstract class Application extends Module
$error = error_get_last();
if (ErrorException::isFatalError($error)) {
unset($this->_memoryReserve);
$exception = new ErrorException($error['message'], $error['type'], $error['type'], $error['file'], $error['line']);
// use error_log because it's too late to use Yii log
error_log($exception);
......
......@@ -192,11 +192,16 @@ class ErrorHandler extends Component
*/
public function renderFile($_file_, $_params_)
{
$_params_['handler'] = $this;
if ($this->exception instanceof ErrorException) {
ob_start();
ob_implicit_flush(false);
extract($_params_, EXTR_OVERWRITE);
require(Yii::getAlias($_file_));
return ob_get_clean();
} else {
return Yii::$app->getView()->renderFile($_file_, $_params_, $this);
}
}
/**
......
......@@ -8,19 +8,19 @@
* @var string[] $lines
* @var integer $begin
* @var integer $end
* @var \yii\base\ErrorHandler $this
* @var \yii\base\ErrorHandler $handler
*/
?>
<li class="<?php if (!$this->isCoreFile($file) || $index === 1) echo 'application'; ?> call-stack-item"
<li class="<?php if (!$handler->isCoreFile($file) || $index === 1) echo 'application'; ?> call-stack-item"
data-line="<?php echo (int)($line - $begin); ?>">
<div class="element-wrap">
<div class="element">
<span class="item-number"><?php echo (int)$index; ?>.</span>
<span class="text"><?php if ($file !== null) echo 'in ' . $this->htmlEncode($file); ?></span>
<span class="text"><?php if ($file !== null) echo 'in ' . $handler->htmlEncode($file); ?></span>
<?php if ($method !== null): ?>
<span class="call">
<?php if ($file !== null) echo '&ndash;' ?>
<?php if ($class !== null) echo $this->addTypeLinks($class) . '::'; ?><?php echo $this->addTypeLinks($method . '()'); ?>
<?php if ($class !== null) echo $handler->addTypeLinks($class) . '::'; ?><?php echo $handler->addTypeLinks($method . '()'); ?>
</span>
<?php endif; ?>
<span class="at"><?php if ($line !== null) echo 'at line'; ?></span>
......@@ -36,7 +36,7 @@
<pre><?php
// fill empty lines with a whitespace to avoid rendering problems in opera
for ($i = $begin; $i <= $end; ++$i) {
echo (trim($lines[$i]) == '') ? " \n" : $this->htmlEncode($lines[$i]);
echo (trim($lines[$i]) == '') ? " \n" : $handler->htmlEncode($lines[$i]);
}
?></pre>
</div>
......
<?php
/**
* @var \Exception $exception
* @var \yii\base\ErrorHandler $this
* @var \yii\base\ErrorHandler $handler
*/
$title = $this->htmlEncode($exception instanceof \yii\base\Exception ? $exception->getName() : get_class($exception));
$title = $handler->htmlEncode($exception instanceof \yii\base\Exception ? $exception->getName() : get_class($exception));
?>
<!DOCTYPE html>
<html>
......@@ -50,16 +50,17 @@ $title = $this->htmlEncode($exception instanceof \yii\base\Exception ? $exceptio
</head>
<body>
<h1><?php echo $title?></h1>
<h2><?php echo nl2br($this->htmlEncode($exception->getMessage()))?></h2>
<p>
<h1><?php echo $title?></h1>
<h2><?php echo nl2br($handler->htmlEncode($exception->getMessage()))?></h2>
<p>
The above error occurred while the Web server was processing your request.
</p>
<p>
</p>
<p>
Please contact us if you think this is a server error. Thank you.
</p>
<div class="version">
</p>
<div class="version">
<?php echo date('Y-m-d H:i:s', time())?>
</div>
</div>
<?php if (method_exists($this, 'endBody')) $this->endBody(); // to allow injecting code into body (mostly by Yii Debug Toolbar) ?>
</body>
</html>
<?php
/**
* @var \yii\base\Exception $exception
* @var \yii\base\ErrorHandler $this
* @var \yii\base\ErrorHandler $handler
*/
?>
<div class="previous">
......@@ -9,13 +9,13 @@
<h2>
<span>Caused by:</span>
<?php if ($exception instanceof \yii\base\Exception): ?>
<span><?php echo $this->htmlEncode($exception->getName()); ?></span> &ndash;
<?php echo $this->addTypeLinks(get_class($exception)); ?>
<span><?php echo $handler->htmlEncode($exception->getName()); ?></span> &ndash;
<?php echo $handler->addTypeLinks(get_class($exception)); ?>
<?php else: ?>
<span><?php echo $this->htmlEncode(get_class($exception)); ?></span>
<span><?php echo $handler->htmlEncode(get_class($exception)); ?></span>
<?php endif; ?>
</h2>
<h3><?php echo $this->htmlEncode($exception->getMessage()); ?></h3>
<h3><?php echo $handler->htmlEncode($exception->getMessage()); ?></h3>
<p>in <span class="file"><?php echo $exception->getFile(); ?></span> at line <span class="line"><?php echo $exception->getLine(); ?></span></p>
<?php echo $this->renderPreviousExceptions($exception); ?>
<?php echo $handler->renderPreviousExceptions($exception); ?>
</div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment