Commit 7c06cc03 by Qiang Xue

finished error handler.

parent dd4c1b77
...@@ -64,7 +64,7 @@ class View extends Component ...@@ -64,7 +64,7 @@ class View extends Component
{ {
$file = $this->findViewFile($view); $file = $this->findViewFile($view);
if ($file !== false) { if ($file !== false) {
return $this->renderFile($file, $params); $this->renderFile($file, $params);
} else { } else {
throw new Exception("Unable to find the view file for view '$view'."); throw new Exception("Unable to find the view file for view '$view'.");
} }
...@@ -72,45 +72,30 @@ class View extends Component ...@@ -72,45 +72,30 @@ class View extends Component
public function renderFile($file, $params = array()) public function renderFile($file, $params = array())
{ {
return $this->renderFileInternal($file, $params); $this->renderFileInternal($file, $params);
} }
public function widget($class, $properties = array(), $returnOutput = false) public function widget($class, $properties = array())
{ {
if ($returnOutput) {
ob_start();
ob_implicit_flush(false);
$widget = $this->createWidget($class, $properties);
$widget->run();
return ob_get_clean();
} else {
$widget = $this->createWidget($class, $properties); $widget = $this->createWidget($class, $properties);
$widget->run(); $widget->run();
return $widget; return $widget;
} }
}
private $_widgetStack = array(); private $_widgetStack = array();
public function beginWidget($class, $properties = array()) public function beginWidget($class, $properties = array())
{ {
ob_start();
ob_implicit_flush(false);
$widget = $this->createWidget($class, $properties); $widget = $this->createWidget($class, $properties);
$this->_widgetStack[] = $widget; $this->_widgetStack[] = $widget;
return $widget; return $widget;
} }
public function endWidget($returnOutput = false) public function endWidget()
{ {
if (($widget = array_pop($this->_widgetStack)) !== null) { if (($widget = array_pop($this->_widgetStack)) !== null) {
$widget->run(); $widget->run();
if ($returnOutput) {
return ob_get_clean();
} else {
ob_end_clean();
return $widget; return $widget;
}
} else { } else {
throw new Exception("Unmatched beginWidget() and endWidget() calls."); throw new Exception("Unmatched beginWidget() and endWidget() calls.");
} }
...@@ -228,10 +213,7 @@ class View extends Component ...@@ -228,10 +213,7 @@ class View extends Component
protected function renderFileInternal($_file_, $_params_ = array()) protected function renderFileInternal($_file_, $_params_ = array())
{ {
extract($_params_, EXTR_OVERWRITE); extract($_params_, EXTR_OVERWRITE);
ob_start();
ob_implicit_flush(false);
require($_file_); require($_file_);
return ob_get_clean();
} }
public function findViewFile($view) public function findViewFile($view)
......
<?php
/**
* @var \Exception $exception
* @var \yii\base\ErrorHandler $owner
*/
$owner = $this->owner;
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title><?php echo get_class($exception); ?></title>
<style type="text/css">
/*<![CDATA[*/
body {
font: normal 9pt "Verdana";
color: #000;
background: #fff;
}
h1 {
font: normal 18pt "Verdana";
color: #f00;
margin-bottom: .5em;
}
h2 {
font: normal 14pt "Verdana";
color: #800000;
margin-bottom: .5em;
}
h3 {
font: bold 11pt "Verdana";
}
p {
font: normal 9pt "Verdana";
color: #000;
}
.version {
color: gray;
font-size: 8pt;
border-top: 1px solid #aaa;
padding-top: 1em;
margin-bottom: 1em;
}
/*]]>*/
</style>
</head>
<body>
<h1><?php echo get_class($exception); ?></h1>
<h2><?php echo nl2br($owner->htmlEncode($exception->getMessage()))?> </h2>
<p>
The above error occurred while the Web server was processing your request.
</p>
<p>
If you think this is a server error, please contact us.
</p>
<p>
Thank you.
</p>
<div class="version">
<?php echo date('Y-m-d H:i:s', time()); ?>
<?php echo YII_DEBUG ? $owner->versionInfo : ''; ?>
</div>
</body>
</html>
\ No newline at end of file
<?php
/**
* @var \Exception $exception
* @var \yii\base\ErrorHandler $owner
*/
$owner = $this->owner;
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title><?php echo get_class($exception); ?></title>
<style type="text/css">
/*<![CDATA[*/
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td{border:0;outline:0;font-size:100%;vertical-align:baseline;background:transparent;margin:0;padding:0;}
body{line-height:1;}
ol,ul{list-style:none;}
blockquote,q{quotes:none;}
blockquote:before,blockquote:after,q:before,q:after{content:none;}
:focus{outline:0;}
ins{text-decoration:none;}
del{text-decoration:line-through;}
table{border-collapse:collapse;border-spacing:0;}
body {
font: normal 9pt "Verdana";
color: #000;
background: #fff;
}
h1 {
font: normal 18pt "Verdana";
color: #f00;
margin-bottom: .5em;
}
h2 {
font: normal 14pt "Verdana";
color: #800000;
margin-bottom: .5em;
}
h3 {
font: bold 11pt "Verdana";
}
pre {
font: normal 11pt Menlo, Consolas, "Lucida Console", Monospace;
}
pre span.error {
display: block;
background: #fce3e3;
}
pre span.ln {
color: #999;
padding-right: 0.5em;
border-right: 1px solid #ccc;
}
pre span.error-ln {
font-weight: bold;
}
.container {
margin: 1em 4em;
}
.version {
color: gray;
font-size: 8pt;
border-top: 1px solid #aaa;
padding-top: 1em;
margin-bottom: 1em;
}
.message {
color: #000;
padding: 1em;
font-size: 11pt;
background: #f3f3f3;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
margin-bottom: 1em;
line-height: 160%;
}
.source {
margin-bottom: 1em;
}
.code pre {
background-color: #ffe;
margin: 0.5em 0;
padding: 0.5em;
line-height: 125%;
border: 1px solid #eee;
}
.source .file {
margin-bottom: 1em;
font-weight: bold;
}
.traces {
margin: 2em 0;
}
.trace {
margin: 0.5em 0;
padding: 0.5em;
}
.trace.app {
border: 1px dashed #c00;
}
.trace .number {
text-align: right;
width: 2em;
padding: 0.5em;
}
.trace .content {
padding: 0.5em;
}
.trace .plus,
.trace .minus {
display: inline;
vertical-align: middle;
text-align: center;
border: 1px solid #000;
color: #000;
font-size: 10px;
line-height: 10px;
margin: 0;
padding: 0 1px;
width: 10px;
height: 10px;
}
.trace.collapsed .minus,
.trace.expanded .plus,
.trace.collapsed pre {
display: none;
}
.trace-file {
cursor: pointer;
padding: 0.2em;
}
.trace-file:hover {
background: #f0ffff;
}
/*]]>*/
</style>
</head>
<body>
<div class="container">
<h1><?php echo get_class($exception); ?></h1>
<p class="message">
<?php echo nl2br($owner->htmlEncode($exception->getMessage()))?>
</p>
<div class="source">
<p class="file">
<?php echo $owner->htmlEncode($exception->getFile()) . '(' . $exception->getLine() . ')'; ?>
</p>
<?php if (YII_DEBUG) $owner->renderSourceCode($exception->getFile(), $exception->getLine(), $owner->maxSourceLines); ?>
</div>
<?php if (YII_DEBUG): ?>
<div class="traces">
<h2>Stack Trace</h2>
<?php $owner->renderTrace($exception->getTrace()); ?>
</div>
<?php endif; ?>
<div class="version">
<?php echo date('Y-m-d H:i:s', time()); ?>
<?php echo YII_DEBUG ? $owner->versionInfo : ''; ?>
</div>
</div>
<script type="text/javascript">
/*<![CDATA[*/
var traceReg = new RegExp("(^|\\s)trace-file(\\s|$)");
var collapsedReg = new RegExp("(^|\\s)collapsed(\\s|$)");
var e = document.getElementsByTagName("div");
for(var j=0,len=e.length;j<len;j++){
if(traceReg.test(e[j].className)){
e[j].onclick = function(){
var trace = this.parentNode.parentNode;
if(collapsedReg.test(trace.className))
trace.className = trace.className.replace("collapsed", "expanded");
else
trace.className = trace.className.replace("expanded", "collapsed");
}
}
}
/*]]>*/
</script>
</body>
</html>
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