Search code examples
symfonydoctrine-odm

Doctrine MongoDB get('doctrine_mongodb')


I've followed official tutorial on how to integrate MongoDB with Doctrine 2 in Symfony 2.8. DoctrineMongoDBBundle, and everything went fine until this point:

In my controller I'm trying to push some data in my MongoDB

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

It fails on $this->get('doctrine_mongodb')->getManager();

Attempted to call an undefined method named "get" of class "AppBundle\Controller\PlaidController".

I've enabled auto_mapping in config.yml

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

This is my first encounter with Symfony and Doctrine, so any tips would be appreciated.


Solution

  • Your controller must extend \Symfony\Bundle\FrameworkBundle\Controller\Controller class to use ->get() (and other helper) method.