[FrameworkBundle][DoctrineBundle] Adding a few shortcut methods
This adds to convience methods, for two separate reasons: * Controller::getDoctrine() - this will allow method completion on the Registry class to work in IDEs, is slightly shorter, and should feel very "concrete" to beginners * Registry::getRepository() - the repository is a very convenient thing to need - this allows it to be fetched much more succintly Overall Before: $product = $this->get('doctrine') ->getEntityManager() ->getRepository('AcmeDemoBundle:Product') ->find($id); Overall After (with IDE method auto-completion for `getRepository`): $product = $this->getDoctrine() ->getRepository('AcmeDemoBundle:Product') ->find($id);
This commit is contained in:
parent
4b86b15105
commit
28dcb3c581
@ -108,6 +108,19 @@ class Registry
|
||||
return $this->container->get($this->entityManagers[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut method to return the EntityRepository for an entity.
|
||||
*
|
||||
* @param string $entityName The name of the entity.
|
||||
* @param string $entityManagerNAme The entity manager name (null for the default one)
|
||||
* @return Doctrine\ORM\EntityRepository
|
||||
*/
|
||||
public function getRepository($entityName, $entityManagerName)
|
||||
{
|
||||
return $this->getEntityManager($entityManagerName)
|
||||
->getRespository($entityName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets a named entity manager.
|
||||
*
|
||||
|
@ -137,6 +137,16 @@ class Controller extends ContainerAware
|
||||
return $this->get('form.factory')->createBuilder('form', $data, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to return the Doctrine Registry class
|
||||
*
|
||||
* @return Symfony\Bundle\DoctrineBundle\Registry
|
||||
*/
|
||||
public function getDoctrine()
|
||||
{
|
||||
return $this->get('doctrine');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the service id is defined.
|
||||
*
|
||||
|
Reference in New Issue
Block a user