/** * 构造函数 * * @access public * @param mixed $config * @return mixed */ public function __construct($config = null) { parent::__construct(null, null, $config); Tiny::setApp($this); if (is_string($config)) { $config = (require $config); } if (!defined('APP_ROOT')) { define('APP_ROOT', dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR); } $this->setBasePath(APP_ROOT . 'protected' . DIRECTORY_SEPARATOR); if (isset($config['extConfig'])) { ExtensionFactory::setExtConfig($config['extConfig']); } if (isset($config['urlFormat'])) { Url::setUrlFormat($config['urlFormat']); } else { Url::setUrlFormat('get'); } //应用url路径 define('APP_URL', Url::baseDir()); if (isset($config['route'])) { Url::setRoute($config['route']); } if (isset($config['name'])) { $this->name = $config['name']; } //设置一些基本路径 if (!defined('APP_URL')) { define('APP_URL', Url::baseDir()); } //扩展的目录 Tiny::setPath('ext', APP_CODE_ROOT . 'extensions'); //项目的缓存目录 Tiny::setPath('cache', APP_ROOT . 'cache'); //项目的数据目录 主要是存放 uploads thumb database等目录 $data_path = APP_ROOT . 'data/'; $data_url = APP_URL . 'data/'; Tiny::setPath('data', $data_path); Tiny::setPath('data_url', $data_url); Tiny::setPath('database', $data_path . 'database/'); Tiny::setPath('database_url', $data_url . 'database/'); Tiny::setPath('uploads', $data_path . 'uploads/'); Tiny::setPath('uploads_url', $data_url . 'uploads/'); Tiny::setPath('thumb', $data_path . 'thumb/'); Tiny::setPath('thumb_url', $data_url . 'thumb/'); //配制一些要引用的文件 //加载用户自己扩展的class类,默认为用户项目下的classes目录 if (isset($config['classes'])) { Tiny::setClasses($config['classes']); } else { Tiny::setClasses('classes.*'); } if (isset($config['imports'])) { Tiny::setImports($config['imports']); } //设置安全码 if (isset($config['safeCode'])) { $this->safeCode = $config['safeCode']; } //加载主题 if (isset($config['theme'])) { Tiny::app()->setTheme($config['theme']); } //加载主题下的皮肤 if (isset($config['skin'])) { Tiny::app()->setSkin($config['skin']); } //用户项目里的错误处理的controller类 if (isset($config['errorsController'])) { Tiny::setErrorsController($config['errorsController']); } else { Tiny::setErrorsController("Error"); } //用户自定义的调试模式 if (isset($config['debug'])) { Tiny::setDebug($config['debug']); } if (isset($config['timezone'])) { $timezone = $config['timezone']; date_default_timezone_set($timezone); } unset($config); }