I have an object from inside a Symfony2 project. Here follows the code.
namespace Acme\UserBundle\Form\Model;
use Symfony\Component\Validator\Constraints as Assert;
use Acme\UserBundle\Entity\User;
class Registration
{
/**
* @Assert\Type(type="Acme\UserBundle\Entity\User")
*/
protected $user;
...
public function setUser(User $user)
{
//Get the EntityManager here!!!!
$group = $em
->getRepository('AcmeUserBundle:Group')
->findOneByName('Customers');
$this->user->addGroup($group);
}
....
}
So, as highlighted in the code, how to get the EntityManager to retrieve an entity with Doctrine?
Thanks in advance
Ok, solved!
I only have to pass the EntityManager to the constructor of the Registration class within the controller.
Thanks a lot anyway.