<?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"); } } } }