Created
May 19, 2011 21:08
-
-
Save bshaffer/981747 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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