return new Phalcon\Db\Adapter\Pdo\Mysql($dbWriteConfig); }); $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);
/** * 设置配置文件 * @param unknown $configs */ public static function config($configs = array()) { self::$configs = $configs; return true; }