Symfony config component and Doctrine dbal

喜欢而已 提交于 2019-12-25 07:46:54

问题


Via composer i installed doctrine dbal and symfony2 config component

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

I autoload them via

 require_once __DIR__ . '/vendor/autoload.php'

Then code goes like this

 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);

Question is how to load Doctrine DBAL configuration from global.yml file ?

来源:https://stackoverflow.com/questions/22398258/symfony-config-component-and-doctrine-dbal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!