【问题标题】:Doctrine MongoDB get('doctrine_mongodb')学说 MongoDB get('doctrine_mongodb')
【发布时间】:2018-03-13 18:21:56
【问题描述】:

我已经关注了如何在 Symfony 2.8 中将 MongoDB 与 Doctrine 2 集成的官方教程。 DoctrineMongoDBBundle,到目前为止一切都很好:

在我的控制器中,我试图将一些数据推送到我的 MongoDB 中

$dm = $this->get('doctrine_mongodb')->getManager();
$account = new Account($value);
$dm->persist($account);
$dm->flush();

$this->get('doctrine_mongodb')->getManager(); 失败

试图调用类的名为“get”的未定义方法 “AppBundle\Controller\PlaidController”。

我在 config.yml 中启用了 auto_mapping

# app/config/config.yml
doctrine_mongodb:
    connections:
        default:
            server: "%mongodb_server%"
            options: {}
    default_database: test_database
    document_managers:
        default:
            auto_mapping: true

这是我第一次接触 Symfony 和 Doctrine,所以任何提示都将不胜感激。

【问题讨论】:

    标签: symfony doctrine-odm


    【解决方案1】:

    您的控制器必须扩展 \Symfony\Bundle\FrameworkBundle\Controller\Controller 类才能使用 ->get()(和其他帮助程序)方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多