Yii Framework v1.1.10 绫诲弬鑰

CErrorHandler

system.base
缁ф壙 class CErrorHandler » CApplicationComponent » CComponent
瀹炵幇 IApplicationComponent
婧愯嚜 1.0
鐗堟湰 $Id: CErrorHandler.php 3540 2012-01-16 10:17:01Z mdomba $
婧愮爜 framework/base/CErrorHandler.php
CErrorHandler鏄敤鏉ュ鐞嗘湭鎹曡幏鐨凱HP閿欒鍜屽紓甯搞

瀹冩牴鎹簲鐢ㄧ▼搴忕殑杩愯妯″紡锛 鏄剧ず鐩稿簲鐨勯敊璇 瀹冮夋嫨浼樺厛鐨勮瑷鏄剧ず閿欒銆

CErrorHandler浣跨敤涓ょ瑙嗗浘锛
  • 寮鍙戣鍥撅紝鍚嶄负exception.php;
  • 鐢熶骇瑙嗗浘锛屽悕涓error<StatusCode>.php;
<StatusCode>琛ㄧずPHP閿欒浠g爜锛堜緥濡俥rror500.php锛夈 鏈湴鍖栬鍥剧殑鍛藉悕鏄夋嫨鍦ㄦ湰鍦拌瑷鐨勫瓙鐩綍涓嬬殑浠g爜 锛堜緥濡傦紝zh_cn/error500.php锛夈

寮鍙戣鍥炬槸褰撳簲鐢ㄧ▼搴忎负璋冭瘯妯″紡鏃舵樉绀虹殑瑙嗗浘 锛堝嵆YII_DEBUG瀹氫箟涓簍rue锛夈 杩欑瑙嗗浘鏄剧ず浜嗚缁嗙殑閿欒淇℃伅鍜屾簮浠g爜銆 鐢熶骇瑙嗗浘鏄綋搴旂敤绋嬪簭涓轰骇鍝佹ā寮忔椂鏄剧ず缁欐渶缁堢敤鎴风殑瑙嗗浘銆 鍑轰簬瀹夊叏鍘熷洜锛屽畠浠彧鏄剧ず浜嗛敊璇俊鎭紝 娌℃湁鍏跺畠鏈哄瘑淇℃伅銆

CErrorHandler鎸変互涓嬮『搴忔煡鎵捐鍥炬ā鏉匡細
  1. themes/ThemeName/views/system: when a theme is active.
  2. protected/views/system
  3. framework/views
濡傛灉鍦ㄧ洰褰曚笅娌℃湁鎵惧埌瑙嗗浘鏂囦欢锛屽畠灏嗗湪涓嬩竴涓洰褰曟煡鎵俱

maxSourceLines灞炴у彲浠ユ寚瀹氬湪寮鍙戣鍥句腑 鏄剧ず鐨勬渶澶ф簮浠g爜琛屾暟銆

CErrorHandler 鏄竴涓牳蹇冨簲鐢ㄧ粍浠讹紝瀹冭兘闅忔椂閫氳繃 CApplication::getErrorHandler()璁块棶銆

鍏叡灞炴

闅愯棌缁ф壙灞炴

灞炴绫诲瀷鎻忚堪瀹氫箟鍦
adminInfo string 搴旂敤绋嬪簭绠$悊鍛樹俊鎭紙鍙互鏄竴涓悕瀛楁垨鐢靛瓙閭欢閾炬帴锛夈傚畠浼氭樉绀哄湪鏈缁堢敤鎴风殑閿欒闈㈤〉锛岄粯璁や负鈥榯he webmaster鈥欍 CErrorHandler
behaviors array 杩欎釜搴旂敤缁勪欢闄勫姞鐨勮涓恒 杩欐琛屼负灏嗗湪搴旂敤缁勪欢璋冪敤init鏃堕檮鍔犲湪搴旂敤缁勪欢涓娿 璇峰弬鐓CModel::behaviors濡備綍鎸囧畾姝ゅ睘鎬у笺 CApplicationComponent
discardOutput boolean 鏄惁鎶涘純閿欒鏄剧ず涔嬪墠鐨勮緭鍑哄唴瀹癸紝榛樿涓簍rue銆 CErrorHandler
error array 杩斿洖褰撳墠姝e湪澶勭悊鐨勯敊璇殑璇︾粏淇℃伅銆 CErrorHandler
errorAction string 琚敤鏉ユ樉绀哄閮ㄩ敊璇俊鎭殑鎺у埗鍏跺姩浣滅殑璺敱锛堜緥濡傗榮ite/error鈥欙級銆 鍦ㄥ姩浣滀腑锛屽畠閫氳繃Yii::app()->errorHandler->error寰楀埌鐩稿叧鐨勯敊璇俊鎭 杩欎釜灞炴ч粯璁や负null锛屾剰鍛崇潃CErrorHandler灏嗗鐞嗛敊璇樉绀恒 CErrorHandler
isInitialized boolean 妫鏌ュ簲鐢ㄧ粍浠舵槸鍚﹀凡缁忓垵濮嬪寲銆 CApplicationComponent
maxSourceLines integer 鏄剧ず鏈澶ф簮浠g爜琛屾暟锛岄粯璁25銆 CErrorHandler
maxTraceSourceLines integer 鏄剧ず鏈澶ц窡韪簮浠g爜琛屾暟锛岄粯璁10銆 CErrorHandler

鍙椾繚鎶ゅ睘鎬

闅愯棌缁ф壙灞炴

灞炴绫诲瀷鎻忚堪瀹氫箟鍦
versionInfo string 杩斿洖鏈嶅姟鐗堟湰淇℃伅銆 CErrorHandler

鍏叡鏂规硶

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
__call() 濡傛灉绫讳腑娌℃湁璋冪殑鏂规硶鍚嶏紝鍒欒皟鐢ㄨ繖涓柟娉曘 CComponent
__get() 杩斿洖涓涓睘鎬у笺佷竴涓簨浠跺鐞嗙▼搴忓垪琛ㄦ垨涓涓涓哄悕绉般 CComponent
__isset() 妫鏌ヤ竴涓睘鎬ф槸鍚︿负null銆 CComponent
__set() 璁剧疆涓涓粍浠剁殑灞炴у笺 CComponent
__unset() 璁剧疆涓涓粍浠剁殑灞炴т负null銆 CComponent
asa() 杩斿洖杩欎釜鍚嶅瓧鐨勮涓哄璞° CComponent
attachBehavior() 闄勫姞涓涓涓哄埌缁勪欢銆 CComponent
attachBehaviors() 闄勫姞涓涓涓哄垪琛ㄥ埌缁勪欢銆 CComponent
attachEventHandler() 涓轰簨浠堕檮鍔犱竴涓簨浠跺鐞嗙▼搴忋 CComponent
canGetProperty() 纭畾灞炴ф槸鍚﹀彲璇汇 CComponent
canSetProperty() 纭畾灞炴ф槸鍚﹀彲鍐欍 CComponent
detachBehavior() 浠庣粍浠朵腑鍒嗙涓涓涓恒 CComponent
detachBehaviors() 浠庣粍浠朵腑鍒嗙鎵鏈夎涓恒 CComponent
detachEventHandler() 鍒嗙涓涓瓨鍦ㄧ殑浜嬩欢澶勭悊绋嬪簭銆 CComponent
disableBehavior() 绂佺敤涓涓檮鍔犺涓恒 CComponent
disableBehaviors() 绂佺敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
enableBehavior() 鍚敤涓涓檮鍔犺涓恒 CComponent
enableBehaviors() 鍚敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
evaluateExpression() 璁$畻涓涓狿HP琛ㄨ揪寮忥紝鎴栨牴鎹粍浠朵笂涓嬫枃鎵ц鍥炶皟銆 CComponent
getError() 杩斿洖褰撳墠姝e湪澶勭悊鐨勯敊璇殑璇︾粏淇℃伅銆 CErrorHandler
getEventHandlers() 杩斿洖涓涓簨浠剁殑闄勫姞澶勭悊绋嬪簭鍒楄〃銆 CComponent
getIsInitialized() 妫鏌ュ簲鐢ㄧ粍浠舵槸鍚﹀凡缁忓垵濮嬪寲銆 CApplicationComponent
handle() 澶勭悊寮傚父/閿欒浜嬩欢銆 CErrorHandler
hasEvent() 纭畾涓涓簨浠舵槸鍚﹀畾涔夈 CComponent
hasEventHandler() 妫鏌ヤ簨浠舵槸鍚︽湁闄勫姞鐨勫鐞嗙▼搴忋 CComponent
hasProperty() 纭畾灞炴ф槸鍚﹁瀹氫箟銆 CComponent
init() 鍒濆鍖栧簲鐢ㄧ粍浠躲 CApplicationComponent
raiseEvent() 鍙戣捣涓涓簨浠躲 CComponent

鍙椾繚鎶ゆ柟娉

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
argumentsToString() 杞崲鍙傛暟鏁扮粍涓哄瓧绗︿覆琛ㄧ幇銆 CErrorHandler
getExactTrace() 杩斿洖闂鍙戠敓鐨勮缁嗚窡韪俊鎭 CErrorHandler
getVersionInfo() 杩斿洖鏈嶅姟鐗堟湰淇℃伅銆 CErrorHandler
getViewFile() 纭畾搴旇浣跨敤鐨勮鍥炬枃浠躲 CErrorHandler
getViewFileInternal() 鏌ョ湅鎸囧畾鐩綍涓嬬殑瑙嗗浘銆 CErrorHandler
handleError() 澶勭悊PHP閿欒銆 CErrorHandler
handleException() 澶勭悊寮傚父銆 CErrorHandler
isAjaxRequest() 褰撳墠璇锋眰鏄惁鏄竴涓狝JAX锛圶MLHttpRequest锛夎姹傘 CErrorHandler
isCoreCode() 杩斿洖鏄惁浠庡簲鐢ㄧ▼搴忎唬鐮佷腑璋冪敤鍫嗘爤銆 CErrorHandler
render() 娓叉煋瑙嗗浘 CErrorHandler
renderSourceCode() 娓叉煋鍥寸粫閿欒琛屾簮浠g爜銆 CErrorHandler

灞炴ц缁

adminInfo 灞炴
public string $adminInfo;

搴旂敤绋嬪簭绠$悊鍛樹俊鎭紙鍙互鏄竴涓悕瀛楁垨鐢靛瓙閭欢閾炬帴锛夈傚畠浼氭樉绀哄湪鏈缁堢敤鎴风殑閿欒闈㈤〉锛岄粯璁や负鈥榯he webmaster鈥欍

discardOutput 灞炴
public boolean $discardOutput;

鏄惁鎶涘純閿欒鏄剧ず涔嬪墠鐨勮緭鍑哄唴瀹癸紝榛樿涓簍rue銆

error 灞炴 鍙
public array getError()

杩斿洖褰撳墠姝e湪澶勭悊鐨勯敊璇殑璇︾粏淇℃伅銆 璇ラ敊璇繑鍥炵殑鏁扮粍鍖呭惈濡備笅淇℃伅锛

errorAction 灞炴
public string $errorAction;

琚敤鏉ユ樉绀哄閮ㄩ敊璇俊鎭殑鎺у埗鍏跺姩浣滅殑璺敱锛堜緥濡傗榮ite/error鈥欙級銆 鍦ㄥ姩浣滀腑锛屽畠閫氳繃Yii::app()->errorHandler->error寰楀埌鐩稿叧鐨勯敊璇俊鎭 杩欎釜灞炴ч粯璁や负null锛屾剰鍛崇潃CErrorHandler灏嗗鐞嗛敊璇樉绀恒

maxSourceLines 灞炴
public integer $maxSourceLines;

鏄剧ず鏈澶ф簮浠g爜琛屾暟锛岄粯璁25銆

maxTraceSourceLines 灞炴 锛堝彲鐢ㄨ嚜 v1.1.6锛
public integer $maxTraceSourceLines;

鏄剧ず鏈澶ц窡韪簮浠g爜琛屾暟锛岄粯璁10銆

versionInfo 灞炴 鍙
protected string getVersionInfo()

杩斿洖鏈嶅姟鐗堟湰淇℃伅銆 濡傛灉搴旂敤鏄敓浜фā寮忥紝灏嗚繑鍥炵┖瀛楃涓层

鏂规硶璇︾粏

argumentsToString() 鏂规硶
protected string argumentsToString(array $args)
$args array 瑕佽浆鎹㈢殑鍙傛暟鏁扮粍
{return} string 鍙傛暟鏁扮粍鐨勫瓧绗︿覆琛ㄧ幇
婧愮爜锛 framework/base/CErrorHandler.php#392 (鏄剧ず)
protected function argumentsToString($args)
{
    
$count=0;

    
$isAssoc=$args!==array_values($args);

    foreach(
$args as $key => $value)
    {
        
$count++;
        if(
$count>=5)
        {
            if(
$count>5)
                unset(
$args[$key]);
            else
                
$args[$key]='...';
            continue;
        }

        if(
is_object($value))
            
$args[$key] = get_class($value);
        else if(
is_bool($value))
            
$args[$key] = $value 'true' 'false';
        else if(
is_string($value))
        {
            if(
strlen($value)>64)
                
$args[$key] = '"'.substr($value,0,64).'..."';
            else
                
$args[$key] = '"'.$value.'"';
        }
        else if(
is_array($value))
            
$args[$key] = 'array('.$this->argumentsToString($value).')';
        else if(
$value===null)
            
$args[$key] = 'null';
        else if(
is_resource($value))
            
$args[$key] = 'resource';

        if(
is_string($key))
        {
            
$args[$key] = '"'.$key.'" => '.$args[$key];
        }
        else if(
$isAssoc)
        {
            
$args[$key] = $key.' => '.$args[$key];
        }
    }
    
$out implode(", "$args);

    return 
$out;
}

杞崲鍙傛暟鏁扮粍涓哄瓧绗︿覆琛ㄧ幇銆

getError() 鏂规硶
public array getError()
{return} array 閿欒璇︾粏淇℃伅锛屽鏋滄病鏈夐敊璇繑鍥瀗ull銆
婧愮爜锛 framework/base/CErrorHandler.php#127 (鏄剧ず)
public function getError()
{
    return 
$this->_error;
}

杩斿洖褰撳墠姝e湪澶勭悊鐨勯敊璇殑璇︾粏淇℃伅銆 璇ラ敊璇繑鍥炵殑鏁扮粍鍖呭惈濡備笅淇℃伅锛

getExactTrace() 鏂规硶
protected array getExactTrace(Exception $exception)
$exception Exception 鏈崟鑾峰埌鐨勫紓甯
{return} array 闂鍑虹幇鐨勮缁嗚窡韪俊鎭
婧愮爜锛 framework/base/CErrorHandler.php#288 (鏄剧ず)
protected function getExactTrace($exception)
{
    
$traces=$exception->getTrace();

    foreach(
$traces as $trace)
    {
        
// property access exception
        
if(isset($trace['function']) && ($trace['function']==='__get' || $trace['function']==='__set'))
            return 
$trace;
    }
    return 
null;
}

杩斿洖闂鍙戠敓鐨勮缁嗚窡韪俊鎭

getVersionInfo() 鏂规硶
protected string getVersionInfo()
{return} string 鏈嶅姟鐗堟湰淇℃伅銆傜敓浜фā寮忓皢杩斿洖绌哄瓧绗︿覆銆
婧愮爜锛 framework/base/CErrorHandler.php#373 (鏄剧ず)
protected function getVersionInfo()
{
    if(
YII_DEBUG)
    {
        
$version='<a href="http://www.yiiframework.com/">Yii Framework</a>/'.Yii::getVersion();
        if(isset(
$_SERVER['SERVER_SOFTWARE']))
            
$version=$_SERVER['SERVER_SOFTWARE'].' '.$version;
    }
    else
        
$version='';
    return 
$version;
}

杩斿洖鏈嶅姟鐗堟湰淇℃伅銆 濡傛灉搴旂敤鏄敓浜фā寮忥紝灏嗚繑鍥炵┖瀛楃涓层

getViewFile() 鏂规硶
protected string getViewFile(string $view, integer $code)
$view string 瑙嗗浘鍚嶏紙鏃犺鏄榚xception鈥欒繕鏄榚rror鈥欙級
$code integer HTTP鐘舵佺爜
{return} string 瑙嗗浘鏂囦欢璺緞
婧愮爜锛 framework/base/CErrorHandler.php#327 (鏄剧ず)
protected function getViewFile($view,$code)
{
    
$viewPaths=array(
        
Yii::app()->getTheme()===null null :  Yii::app()->getTheme()->getSystemViewPath(),
        
Yii::app() instanceof CWebApplication Yii::app()->getSystemViewPath() : null,
        
YII_PATH.DIRECTORY_SEPARATOR.'views',
    );

    foreach(
$viewPaths as $i=>$viewPath)
    {
        if(
$viewPath!==null)
        {
             
$viewFile=$this->getViewFileInternal($viewPath,$view,$code,$i===2?'en_us':null);
             if(
is_file($viewFile))
                  return 
$viewFile;
        }
    }
}

纭畾搴旇浣跨敤鐨勮鍥炬枃浠躲

getViewFileInternal() 鏂规硶
protected string getViewFileInternal(string $viewPath, string $view, integer $code, string $srcLanguage=NULL)
$viewPath string 鍖呭惈瑙嗗浘鐨勭洰褰
$view string 瑙嗗浘鍚嶏紙鏃犺鏄榚xception鈥欒繕鏄榚rror鈥欙級
$code integer HTTP鐘舵佺爜
$srcLanguage string 瑙嗗浘鏂囦欢鐨勮瑷
{return} string 瑙嗗浘鏂囦欢鐨勮矾寰
婧愮爜锛 framework/base/CErrorHandler.php#354 (鏄剧ず)
protected function getViewFileInternal($viewPath,$view,$code,$srcLanguage=null)
{
    
$app=Yii::app();
    if(
$view==='error')
    {
        
$viewFile=$app->findLocalizedFile($viewPath.DIRECTORY_SEPARATOR."error{$code}.php",$srcLanguage);
        if(!
is_file($viewFile))
            
$viewFile=$app->findLocalizedFile($viewPath.DIRECTORY_SEPARATOR.'error.php',$srcLanguage);
    }
    else
        
$viewFile=$viewPath.DIRECTORY_SEPARATOR."exception.php";
    return 
$viewFile;
}

鏌ョ湅鎸囧畾鐩綍涓嬬殑瑙嗗浘銆

handle() 鏂规硶
public void handle(CEvent $event)
$event CEvent 鍖呭惈寮傚父/閿欒淇℃伅鐨勪簨浠
婧愮爜锛 framework/base/CErrorHandler.php#93 (鏄剧ず)
public function handle($event)
{
    
// set event as handled to prevent it from being handled by other event handlers
    
$event->handled=true;

    if(
$this->discardOutput)
    {
        
// the following manual level counting is to deal with zlib.output_compression set to On
        
for($level=ob_get_level();$level>0;--$level)
        {
            @
ob_end_clean();
        }
    }

    if(
$event instanceof CExceptionEvent)
        
$this->handleException($event->exception);
    else 
// CErrorEvent
        
$this->handleError($event);
}

澶勭悊寮傚父/閿欒浜嬩欢銆 褰撴崟鑾峰埌寮傚父鎴朠HP閿欒鏃 璋冪敤姝ゆ柟娉曘

handleError() 鏂规硶
protected void handleError(CErrorEvent $event)
$event CErrorEvent PHP閿欒浜嬩欢
婧愮爜锛 framework/base/CErrorHandler.php#200 (鏄剧ず)
protected function handleError($event)
{
    
$trace=debug_backtrace();
    
// skip the first 3 stacks as they do not tell the error position
    
if(count($trace)>3)
        
$trace=array_slice($trace,3);
    
$traceString='';
    foreach(
$trace as $i=>$t)
    {
        if(!isset(
$t['file']))
            
$trace[$i]['file']='unknown';

        if(!isset(
$t['line']))
            
$trace[$i]['line']=0;

        if(!isset(
$t['function']))
            
$trace[$i]['function']='unknown';

        
$traceString.="#$i {$trace[$i]['file']}({$trace[$i]['line']}): ";
        if(isset(
$t['object']) && is_object($t['object']))
            
$traceString.=get_class($t['object']).'->';
        
$traceString.="{$trace[$i]['function']}()\n";

        unset(
$trace[$i]['object']);
    }

    
$app=Yii::app();
    if(
$app instanceof CWebApplication)
    {
        switch(
$event->code)
        {
            case 
E_WARNING:
                
$type 'PHP warning';
                break;
            case 
E_NOTICE:
                
$type 'PHP notice';
                break;
            case 
E_USER_ERROR:
                
$type 'User error';
                break;
            case 
E_USER_WARNING:
                
$type 'User warning';
                break;
            case 
E_USER_NOTICE:
                
$type 'User notice';
                break;
            case 
E_RECOVERABLE_ERROR:
                
$type 'Recoverable error';
                break;
            default:
                
$type 'PHP error';
        }
        
$this->_error=$data=array(
            
'code'=>500,
            
'type'=>$type,
            
'message'=>$event->message,
            
'file'=>$event->file,
            
'line'=>$event->line,
            
'trace'=>$traceString,
            
'traces'=>$trace,
        );
        if(!
headers_sent())
            
header("HTTP/1.0 500 PHP Error");
        if(
$this->isAjaxRequest())
            
$app->displayError($event->code,$event->message,$event->file,$event->line);
        else if(
YII_DEBUG)
            
$this->render('exception',$data);
        else
            
$this->render('error',$data);
    }
    else
        
$app->displayError($event->code,$event->message,$event->file,$event->line);
}

澶勭悊PHP閿欒銆

handleException() 鏂规硶
protected void handleException(Exception $exception)
$exception Exception 鎹曡幏鐨勫紓甯
婧愮爜锛 framework/base/CErrorHandler.php#136 (鏄剧ず)
protected function handleException($exception)
{
    
$app=Yii::app();
    if(
$app instanceof CWebApplication)
    {
        if((
$trace=$this->getExactTrace($exception))===null)
        {
            
$fileName=$exception->getFile();
            
$errorLine=$exception->getLine();
        }
        else
        {
            
$fileName=$trace['file'];
            
$errorLine=$trace['line'];
        }

        
$trace $exception->getTrace();

        foreach(
$trace as $i=>$t)
        {
            if(!isset(
$t['file']))
                
$trace[$i]['file']='unknown';

            if(!isset(
$t['line']))
                
$trace[$i]['line']=0;

            if(!isset(
$t['function']))
                
$trace[$i]['function']='unknown';

            unset(
$trace[$i]['object']);
        }

        
$this->_error=$data=array(
            
'code'=>($exception instanceof CHttpException)?$exception->statusCode:500,
            
'type'=>get_class($exception),
            
'errorCode'=>$exception->getCode(),
            
'message'=>$exception->getMessage(),
            
'file'=>$fileName,
            
'line'=>$errorLine,
            
'trace'=>$exception->getTraceAsString(),
            
'traces'=>$trace,
        );

        if(!
headers_sent())
            
header("HTTP/1.0 {$data['code']} ".get_class($exception));

        if(
$exception instanceof CHttpException || !YII_DEBUG)
            
$this->render('error',$data);
        else
        {
            if(
$this->isAjaxRequest())
                
$app->displayException($exception);
            else
                
$this->render('exception',$data);
        }
    }
    else
        
$app->displayException($exception);
}

澶勭悊寮傚父銆

isAjaxRequest() 鏂规硶
protected boolean isAjaxRequest()
{return} boolean 褰撳墠璇锋眰鏄惁鏄疉JAX璇锋眰銆
婧愮爜锛 framework/base/CErrorHandler.php#278 (鏄剧ず)
protected function isAjaxRequest()
{
    return isset(
$_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH']==='XMLHttpRequest';
}

褰撳墠璇锋眰鏄惁鏄竴涓狝JAX锛圶MLHttpRequest锛夎姹傘

isCoreCode() 鏂规硶
protected boolean isCoreCode(array $trace)
$trace array 璺熻釜鏁版嵁
{return} boolean 鏄惁浠庡簲鐢ㄧ▼搴忎唬鐮佷腑璋冪敤鍫嗘爤銆
婧愮爜锛 framework/base/CErrorHandler.php#447 (鏄剧ず)
protected function isCoreCode($trace)
{
    if(isset(
$trace['file']))
    {
        
$systemPath=realpath(dirname(__FILE__).'/..');
        return 
$trace['file']==='unknown' || strpos(realpath($trace['file']),$systemPath.DIRECTORY_SEPARATOR)===0;
    }
    return 
false;
}

杩斿洖鏄惁浠庡簲鐢ㄧ▼搴忎唬鐮佷腑璋冪敤鍫嗘爤銆

render() 鏂规硶
protected void render(string $view, array $data)
$view string 瑙嗗浘鍚嶏紙涓嶅甫鎵╁睍鍚嶇殑鏂囦欢鍚嶏級銆 鍙傝getViewFile濡備綍瀹氫綅瑙嗗浘鏂囦欢銆
$data array 浼犻掔粰瑙嗗浘鐨勬暟鎹
婧愮爜锛 framework/base/CErrorHandler.php#307 (鏄剧ず)
protected function render($view,$data)
{
    if(
$view==='error' && $this->errorAction!==null)
        
Yii::app()->runController($this->errorAction);
    else
    {
        
// additional information to be passed to view
        
$data['version']=$this->getVersionInfo();
        
$data['time']=time();
        
$data['admin']=$this->adminInfo;
        include(
$this->getViewFile($view,$data['code']));
    }
}

娓叉煋瑙嗗浘

renderSourceCode() 鏂规硶
protected string renderSourceCode(string $file, integer $errorLine, integer $maxLines)
$file string 婧愭枃浠惰矾寰
$errorLine integer 閿欒琛屽彿
$maxLines integer 鏄剧ず鏈澶ц鏁
{return} string 娓叉煋缁撴灉
婧愮爜锛 framework/base/CErrorHandler.php#464 (鏄剧ず)
protected function renderSourceCode($file,$errorLine,$maxLines)
{
    
$errorLine--;    // adjust line number to 0-based from 1-based
    
if($errorLine<|| ($lines=@file($file))===false || ($lineCount=count($lines))<=$errorLine)
        return 
'';

    
$halfLines=(int)($maxLines/2);
    
$beginLine=$errorLine-$halfLines>$errorLine-$halfLines:0;
    
$endLine=$errorLine+$halfLines<$lineCount?$errorLine+$halfLines:$lineCount-1;
    
$lineNumberWidth=strlen($endLine+1);

    
$output='';
    for(
$i=$beginLine;$i<=$endLine;++$i)
    {
        
$isErrorLine $i===$errorLine;
        
$code=sprintf("<span class=\"ln".($isErrorLine?' error-ln':'')."\">%0{$lineNumberWidth}d</span> %s",$i+1,CHtml::encode(str_replace("\t",'    ',$lines[$i])));
        if(!
$isErrorLine)
            
$output.=$code;
        else
            
$output.='<span class="error">'.$code.'</span>';
    }
    return 
'<div class="code"><pre>'.$output.'</pre></div>';
}

娓叉煋鍥寸粫閿欒琛屾簮浠g爜銆

Copyright © 2008-2011 by Yii Software LLC
All Rights Reserved.