gpt4 book ai didi

mongodb - Symfony2 + DoctrineMongoDBBundle 配置

转载 作者:IT老高 更新时间:2023-10-28 12:32:29 25 4
gpt4 key购买 nike

我正在尝试以这种方式将 Symfony 2 与 MongoDB 连接:

  1. AppKernel::registerBundles 中注册 DoctrineMongoDBBundle方法
  2. 设置'doctrine_mongo_db'配置(见下文config.yml)
  3. 从容器中获取'doctrine.odm.mongodb.document_manager'HelloController Action

当我尝试运行应用程序时 MongoConnectionException 被抛出。

谁能帮我解决这个问题?


AppKernel.php

public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\DoctrineMongoDBBundle\DoctrineMongoDBBundle(),
new Sensio\HelloBundle\HelloBundle()
);

return $bundles;
}

config.yml

framework:
charset: UTF-8
router: { resource: "%kernel.root_dir%/config/routing.yml" }
templating: { engines: ['twig'] }

## Doctrine Configuration

doctrine_mongo_db:
server: mongodb://root:root@192.168.0.111:27017
default_database: test
options: { connect: true }
mappings:
HelloBundle: { type: annotation, dir: Document }

# Twig Configuration

twig:
debug: %kernel.debug%
strict_variables: %kernel.debug%

HelloController.php

/* @var $dm \Doctrine\ODM\MongoDB\DocumentManager */
$dm = $this->get('doctrine.odm.mongodb.document_manager');

异常(第 96 行)

connecting to failed: Transport endpoint is not connected

in ~/vendor/doctrine-mongodb/lib/Doctrine/MongoDB/Connection.php line 96 »

93. if ($this->server) {
94. $this->mongo = new \Mongo($this->server, $this->options);
95. } else {
96. $this->mongo = new \Mongo();
97. }

最佳答案

问题在于 DoctrineMongoDBBundle 配置加载。修复 (https://github.com/fabpot/symfony/pull/740) 应该很快被合并。

现在你可以使用下面的固定方法。

public function load(array $configs, ContainerBuilder $container)
{
$mergedConfig = array();
foreach ($configs as $config) {
$mergedConfig = array_merge_recursive($mergedConfig, $config);
}

$this->doMongodbLoad($mergedConfig, $container);
}

关于mongodb - Symfony2 + DoctrineMongoDBBundle 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5162079/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com