public function __construct() { $className = get_class($this); //默认连接的数据库配置项 $dbName = "DEFAULT_DB"; //判断子类是否有getSource方法,如果有,代表要设置新的数据库配置项 $hasSourceMethod = method_exists($this, "getSource"); if ($hasSourceMethod) { $dbName = $this->getSource(); } $tableName = toUnderLineName(getClassFileName($className)); $this->_className = $tableName; $db = M($tableName, $dbName); $this->_db = $db; }
/** * 系统初始化函数,主要初始化smarty模板引擎,定义一些主要的全局模板路径 * @param $c 控制器名称 */ public function _sys_init_action($c) { $this->smt = new Smarty(); $this->smt->left_delimiter = "{"; $this->smt->right_delimiter = "}"; //模板目录,模板命名为方法名驼峰转下划线,再小写 $tmpDir = APP_PATH . "/tpl/" . strtolower(toUnderLineName($c)); //模板编译缓存目录 $cmpDir = TEMP_PATH . "/tpl_c"; $this->smt->setTemplateDir($tmpDir)->setCompileDir($cmpDir); //定义程序相对路径 $this->smt->assign("myf_path", getBasePath()); //定义程序绝对URL路径 $this->smt->assign("myf_full_url", getFullURL()); //定义程序根目录绝对URL路径 $this->smt->assign("myf_project_url", getProjectURL()); }