Skip to content

Instantly share code, notes, and snippets.

@umpirsky
Created October 23, 2012 16:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save umpirsky/3939837 to your computer and use it in GitHub Desktop.
Save umpirsky/3939837 to your computer and use it in GitHub Desktop.
Use the entity form type in Silex
<?php
$app['form.extensions'] = $app->share($this->extend('form.extensions', function ($extensions) {
$managerRegistry = new ManagerRegistry(null, array(), array('doctrine_orm.em'), null, null, $app['doctrine_orm.proxies_namespace']);
$managerRegistry->setContainer($app);
$extensions[] = new DoctrineOrmExtension($managerRegistry);
return $extensions;
}));
<?php
namespace Umpirsky\Doctrine\Common\Persistance;
use Doctrine\Common\Persistence\AbstractManagerRegistry;
use Silex\Application;
/**
* References Doctrine connections and entity/document managers.
*
* @author Саша Стаменковић <umpirsky@gmail.com>
*/
class ManagerRegistry extends AbstractManagerRegistry
{
/**
* @var Application
*/
protected $container;
protected function getService($name)
{
return $this->container[$name];
}
protected function resetService($name)
{
unset($this->container[$name]);
}
public function getAliasNamespace($alias)
{
throw new \BadMethodCallException('Namespace aliases not supported.');
}
public function setContainer(Application $container)
{
$this->container = $container;
}
}
@palmasev
Copy link

palmasev commented Dec 4, 2012

$managerRegistry = new ManagerRegistry(null, array(), array('doctrine_orm.em'), null, null, $app['doctrine_orm.proxies_namespace']); doesn't work.

I use:
$managerRegistry = new ManagerRegistry(null, array(), array('doctrine_orm.em'), null, null, '\Doctrine\ORM\Proxy\Proxy');

@jmontoyaa
Copy link

replace $this->extend with $app->extend

and add $app here:

function ($extensions, $app)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment