/** * @brief 执行视图渲染 * @return 视图 */ public function run() { $controller = $this->getController(); IInterceptor::run("onCreateView", $controller); $this->resolveView($this->getView()); $data = null; if (file_exists($this->view . $controller->extend)) { $controller->render($this->view, $data); } else { $path = $this->view . $controller->extend; $path = IException::pathFilter($path); IError::show("not found this view page({$path})", 404); } IInterceptor::run("onFinishView"); }
/** * @brief 解析视图路径 * @param string $viewPath 视图名称 * @return bool */ public function resolveView($viewPath) { if (preg_match('/^\\w[\\w\\-]*$/', $viewPath)) { //分割模板目录的层次 $view = strtr($viewPath, '-', '/'); $this->basePath = $this->getController()->getViewFile($view); if ($this->basePath) { $this->view = $this->basePath; return; } } else { $viewPath = IException::pathFilter($viewPath); throw new IHttpException("the view filename({$viewPath}) is wrong", 403); } }
/** * @brief 执行视图渲染 * @return 视图 */ public function run() { $controller = $this->getController(); IInterceptor::run("onCreateView", $controller); $this->resolveView($this->getView()); $data = null; if (file_exists($this->view . $controller->extend)) { $controller->render($this->view, $data); } else { $path = $this->view . $controller->extend; $path = IException::pathFilter($path); $data = array('title' => 'HTTP 404', 'heading' => 'not found', 'message' => "not found this view page({$path})"); throw new IHttpException($data, 404); } IInterceptor::run("onFinishView"); }
/** * @brief 设置调试模式 * @param $flag true开启,false关闭 */ private function setDebugMode($flag) { $basePath = $this->getBasePath(); if (function_exists("ini_set")) { ini_set("display_errors", $flag ? "on" : "off"); } if ($flag === true) { error_reporting(E_ALL | E_STRICT); IException::setDebugMode(true); } else { error_reporting(0); IException::setDebugMode(false); } set_error_handler("IException::phpError", E_ALL | E_STRICT); set_exception_handler("IException::phpException"); IException::setLogPath($basePath . "backup/errorLog/" . date("y-m-d") . ".log"); }
/** * Process an exception. * @param \DaFramework\Controller\Tools\Exception\IException $exception The exception to process. */ public function processException(IException $exception) { error_log($exception->getMessage(), 0); }
public static function setDebugMode($mode) { self::$debugMode = $mode; }