/** * 加载文件 * * @param string $name */ public static function load($class_name) { if (self::checkClass($class_name)) { return true; } // add to class map self::addClass(str_replace('/', '_', $class_name)); $file = dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $class_name) . '.php'; if (!is_file($file)) { CError::show('COULD NOT FOUND THE FILE ' . $file); } require $file; }
/** * 启动控制器 * */ public function runController() { $cBuilder = Imp::app()->instance('mvcBuilder')->controllerBuilder(); $cBuilder->init(); $cFile = $cBuilder->file(); $cName = $cBuilder->controller(); $cAction = $cBuilder->action(); $cParams = $cBuilder->params(); $config = Imp::app()->instance('config')->get(); if (!is_file($cFile)) { if ($config['debug']) { CError::show("Controller file \"<font color=\"red\">{$cFile}</font>\" not found"); } else { View::show404(); } return; } // 应用基类 $myController = Imp::app()->basePath() . '/MyController/BaseController.php'; if (is_file($myController)) { require $myController; } require $cFile; if (!class_exists($cName)) { if ($config['debug']) { Error::show(Error::getError(Error::$errorType['no_controller']) . ': ' . $cName); } else { View::show404(); } } // 检查最终的控制器及其方法 if (!method_exists($cName, $cAction)) { Imp::app()->instance('router')->unShiftParams($cAction); $cAction = Imp::app()->instance('config')->get('default_action'); $cParams = Imp::app()->instance('router')->getParams(); Imp::app()->instance('router')->setAction($cAction); } // action 钩子 Imp::app()->instance('hook')->call('action'); // 实例化操作模块 $cInstance = new $cName(); // 检查最终的控制器及其方法 if (!method_exists($cInstance, $cAction)) { if ($config['debug']) { Error::show(Error::getError(Error::$errorType['no_action']) . ': ' . $cAction); } else { View::show404(); } return; } // 调用当前控制器方法 call_user_func_array(array($cInstance, $cAction), $cParams); }
/** * query sql * * @param string $sql */ public function query($sql) { $this->clearCondition(); if (empty($sql)) { CError::show("query sql is empty."); die; } $this->logSqls($sql); try { $this->_query = $this->_link->query($sql); if ($this->_query === false) { $this->transactionCommit = false; CError::show($this->getError() . ' <br/>SQL: ' . $sql); return; } } catch (Exception $e) { $this->transactionCommit = false; CError::show($this->getError() . ' <br/>SQL: ' . $sql); return; } return $this->_query; }