/** * 加载配置文件 * @param type $config */ public static function config($config = array()) { $config['version'] = isset($config['version']) ? $config['version'] : date('Ymd') . '01'; self::$config = $config; return self::instance(); }
$dbReadConfig = current($currentConfig['reads']); $di->set($keyRead, function () use($dbReadConfig) { return new Phalcon\Db\Adapter\Pdo\Mysql($dbReadConfig); }); } //设置默认数据库连接 $defaultDbKey = 'db' . ucfirst($config->balanceDb->default); $di->set('db', $di->get($defaultDbKey)); $defaultDbKey = 'db' . ucfirst($config->balanceDb->default); $di->set('db_read', $di->get($defaultDbKey . '_read')); //加载DB负载均衡 BalanceDb::config($config->balanceDb->toArray()); //Redis负载均衡 BalanceRedis::config($config->balanceRedis->toArray()); //URL 工具类 TUrl::config($config->url->toArray()); //config 工具类 TConfig::instance()->setAll($config->toArray()); //实例化应用 $application = new \Phalcon\Mvc\Application($di); //注册模块 $modules = array(); foreach ($config->modules as $key => $params) { if ($key == 'default') { continue; } $modules[$key] = array('className' => sprintf('Module\\%s\\Module', ucfirst($key)), 'path' => $params['path']); } $application->registerModules($modules); echo $application->handle()->getContent(); } catch (\Exception $e) {