Symfony配置组件和Doctrine dbal

时间:2014-03-14 07:03:58

标签: php symfony doctrine config symfony-components

通过作曲家我安装了doctrine dbal和symfony2配置组件

"require":{
    "symfony/dependency-injection": "2.4.*",
    "symfony/filesystem": "2.4.*",
    "symfony/config": "2.4.*",
    "doctrine/dbal": "2.3.4"
}

我通过

自动加载它们
 require_once __DIR__ . '/vendor/autoload.php'

然后代码就像这样

 use Symfony\Component\DependencyInjection\ContainerBuilder;
 $container = new ContainerBuilder();
 $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/app/config/'));
 $loader->load('global.yml');

 $config = new \Doctrine\DBAL\Configuration();
 $connectionParams = array(
    'dbname' => 'mydb',
    'user' => 'root',
    'password' => 'qwerty',
    'host' => 'localhost',
    'driver' => 'pdo_mysql',
 );
 $conn = DriverManager::getConnection($connectionParams, $config);

问题是如何从global.yml文件加载Doctrine DBAL配置?

0 个答案:

没有答案