WebApplication.php
2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* This is main web application component
*/
class WebApplication extends CWebApplication {
private $_controllerPath;
private $_viewPath;
private $_systemViewPath;
private $_layoutPath;
private $_controller;
private $_theme;
protected function init()
{
register_shutdown_function(array($this, 'onShutdownHandler'));
parent::init();
}
public function onShutdownHandler()
{
// 1. error_get_last() returns NULL if error handled via set_error_handler
// 2. error_get_last() returns error even if error_reporting level less then error
$e = error_get_last();
$errorsToHandle = E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING;
if(!is_null($e) && ($e['type'] & $errorsToHandle)) {
$msg = 'Fatal error: '.$e['message'];
// it's better to set errorAction = null to use system view "error.php" instead of run another controller/action (less possibility of additional errors)
yii::app()->errorHandler->errorAction = null;
// handling error
yii::app()->handleError($e['type'], $msg, $e['file'], $e['line']);
}
}
/**
* Creates the controller and performs the specified action.
* @param string $route the route of the current request. See {@link createController} for more details.
* @throws CHttpException if the controller could not be created.
*/
public function runController($route)
{
if(($ca=$this->createController($route))!==null)
{
list($controller,$actionID)=$ca;
$oldController=$this->_controller;
$this->_controller=$controller;
$controller->init();
$controller->run($actionID);
$this->_controller=$oldController;
}
else {
if(Yii::app()->request->isAjaxRequest) {
throw new CHttpException(404,Yii::t('yii','Unable to resolve the request "{route}".',
array('{route}'=>$route===''?$this->defaultController:$route)));
}
else {
$this->runController($this->defaultController . "/index");
}
}
}
}