CErrorHandler
包 | system.base |
---|---|
继承 | class CErrorHandler » CApplicationComponent » CComponent |
实现 | IApplicationComponent |
可用自 | 1.0 |
版本 | $Id$ |
It displays these errors using appropriate views based on the nature of the error and the mode the application runs at. It also chooses the most preferred language for displaying the error.
CErrorHandler uses two sets of views:
- development views, named as
exception.php
; - production views, named as
error<StatusCode>.php
;
Development views are displayed when the application is in debug mode (i.e. YII_DEBUG is defined as true). Detailed error information with source code are displayed in these views. Production views are meant to be shown to end-users and are used when the application is in production mode. For security reasons, they only display the error message without any sensitive information.
CErrorHandler looks for the view templates from the following locations in order:
themes/ThemeName/views/system
: when a theme is active.protected/views/system
framework/views
The property maxSourceLines can be changed to specify the number of source code lines to be displayed in development views.
CErrorHandler is a core application component that can be accessed via CApplication::getErrorHandler().
公共属性
属性 | 类型 | 描述 | 被定义在 |
---|---|---|---|
adminInfo | string | the application administrator information (could be a name or email link). | CErrorHandler |
behaviors | array | the behaviors that should be attached to this component. | CApplicationComponent |
discardOutput | boolean | whether to discard any existing page output before error display. | CErrorHandler |
error | array | Returns the details about the error that is currently being handled. | CErrorHandler |
errorAction | string | the route (e. | CErrorHandler |
isInitialized | boolean | whether this application component has been initialized (i. | CApplicationComponent |
maxSourceLines | integer | maximum number source code lines to be displayed. | CErrorHandler |
公共方法
方法 | 描述 | 被定义在 |
---|---|---|
__call() | Calls the named method which is not a class method. | CComponent |
__get() | Returns a property value, an event handler list or a behavior based on its name. | CComponent |
__isset() | Checks if a property value is null. | CComponent |
__set() | Sets value of a component property. | CComponent |
__unset() | Sets a component property to be null. | CComponent |
asa() | Returns the named behavior object. | CComponent |
attachBehavior() | Attaches a behavior to this component. | CComponent |
attachBehaviors() | Attaches a list of behaviors to the component. | CComponent |
attachEventHandler() | Attaches an event handler to an event. | CComponent |
canGetProperty() | Determines whether a property can be read. | CComponent |
canSetProperty() | Determines whether a property can be set. | CComponent |
detachBehavior() | Detaches a behavior from the component. | CComponent |
detachBehaviors() | Detaches all behaviors from the component. | CComponent |
detachEventHandler() | Detaches an existing event handler. | CComponent |
disableBehavior() | Disables an attached behavior. | CComponent |
disableBehaviors() | Disables all behaviors attached to this component. | CComponent |
enableBehavior() | Enables an attached behavior. | CComponent |
enableBehaviors() | Enables all behaviors attached to this component. | CComponent |
getError() | Returns the details about the error that is currently being handled. | CErrorHandler |
getEventHandlers() | Returns the list of attached event handlers for an event. | CComponent |
getIsInitialized() | CApplicationComponent | |
handle() | Handles the exception/error event. | CErrorHandler |
hasEvent() | Determines whether an event is defined. | CComponent |
hasEventHandler() | Checks whether the named event has attached handlers. | CComponent |
hasProperty() | Determines whether a property is defined. | CComponent |
init() | Initializes the application component. | CApplicationComponent |
raiseEvent() | Raises an event. | CComponent |
受保护的方法
方法 | 描述 | 被定义在 |
---|---|---|
getExactTrace() | CErrorHandler | |
getSourceLines() | Returns the source lines around the error line. | CErrorHandler |
getVersionInfo() | CErrorHandler | |
getViewFile() | Determines which view file should be used. | CErrorHandler |
getViewFileInternal() | Looks for the view under the specified directory. | CErrorHandler |
handleError() | Handles the PHP error. | CErrorHandler |
handleException() | Handles the exception. | CErrorHandler |
render() | Renders the view. | CErrorHandler |
属性详情
the application administrator information (could be a name or email link). It is displayed in error pages to end users. Defaults to 'the webmaster'.
whether to discard any existing page output before error display. Defaults to true.
Returns the details about the error that is currently being handled. The error is returned in terms of an array, with the following information:
- code - the HTTP status code (e.g. 403, 500)
- type - the error type (e.g. 'CHttpException', 'PHP Error')
- message - the error message
- file - the name of the PHP script file where the error occurs
- line - the line number of the code where the error occurs
- trace - the call stack of the error
- source - the context source code where the error occurs
the route (e.g. 'site/error') to the controller action that will be used to display external errors. Inside the action, it can retrieve the error information by Yii::app()->errorHandler->error. This property defaults to null, meaning CErrorHandler will handle the error display.
maximum number source code lines to be displayed. Defaults to 25.
server version information. If the application is in production mode, nothing is returned.
方法详情
public array getError()
| ||
{return} | array | the error details. Null if there is no error. |
Returns the details about the error that is currently being handled. The error is returned in terms of an array, with the following information:
- code - the HTTP status code (e.g. 403, 500)
- type - the error type (e.g. 'CHttpException', 'PHP Error')
- message - the error message
- file - the name of the PHP script file where the error occurs
- line - the line number of the code where the error occurs
- trace - the call stack of the error
- source - the context source code where the error occurs
protected array getExactTrace(Exception $exception)
| ||
$exception | Exception | the uncaught exception |
{return} | array | the exact trace where the problem occurs |
protected array getSourceLines(string $file, integer $line)
| ||
$file | string | source file path |
$line | integer | the error line number |
{return} | array | source lines around the error line, indxed by line numbers |
Returns the source lines around the error line. At most maxSourceLines lines will be returned.
protected string getVersionInfo()
| ||
{return} | string | server version information. If the application is in production mode, nothing is returned. |
protected string getViewFile(string $view, integer $code)
| ||
$view | string | view name (either 'exception' or 'error') |
$code | integer | HTTP status code |
{return} | string | view file path |
Determines which view file should be used.
protected string getViewFileInternal(string $viewPath, string $view, integer $code, string $srcLanguage=NULL)
| ||
$viewPath | string | the directory containing the views |
$view | string | view name (either 'exception' or 'error') |
$code | integer | HTTP status code |
$srcLanguage | string | the language that the view file is in |
{return} | string | view file path |
Looks for the view under the specified directory.
public void handle(CEvent $event)
| ||
$event | CEvent | the event containing the exception/error information |
Handles the exception/error event. This method is invoked by the application whenever it captures an exception or PHP error.
protected void handleError(CErrorEvent $event)
| ||
$event | CErrorEvent | the PHP error event |
Handles the PHP error.
protected void handleException(Exception $exception)
| ||
$exception | Exception | the exception captured |
Handles the exception.
protected void render(string $view, array $data)
| ||
$view | string | the view name (file name without extension). See getViewFile for how a view file is located given its name. |
$data | array | data to be passed to the view |
Renders the view.