Skip to content

Instantly share code, notes, and snippets.

@bshaffer
Created May 19, 2011 21:08
Show Gist options
  • Save bshaffer/981747 to your computer and use it in GitHub Desktop.
Save bshaffer/981747 to your computer and use it in GitHub Desktop.
<?php
namespace Acme\DemoBundle\Controller;
use Acme\DemoBundle\Documents\User;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ODM\MongoDB\Configuration;
use Doctrine\MongoDB\Connection;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;
class SomeController extends Controller
{
public function someAction()
{
$config = new Configuration();
$config->setProxyDir(__DIR__ . '/../Proxies');
$config->setProxyNamespace('Proxies');
$config->setHydratorDir(__DIR__ . '/../Hydrator');
$config->setHydratorNamespace('Hydrator');
$reader = new AnnotationReader();
$reader->setDefaultAnnotationNamespace('Doctrine\ODM\MongoDB\Mapping\\');
$config->setMetadataDriverImpl(new AnnotationDriver($reader, __DIR__ . '/../Documents'));
$dm = DocumentManager::create(new Connection(), $config);
// Add a User
$user = new User();
$user->setName('Brent');
$user->setEmail('[email protected]');
$dm->persist($user);
$dm->flush();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment