ユーザー登録後にユーザープロファイルを自動作成できるようにしたいです。ユーザー プロファイル オブジェクトを作成する post persist 関数を添付しましたが、オブジェクトを永続化するためのエンティティ マネージャーにアクセスできません。これについて最善の方法は何ですか?
//user.php
/**
* @ORM\PostPersist()
*/
public function PostPersistAction()
{
//create a user profile when a user is created.
$userprofile = new Profile();
$userprofile->setCreatedAt(new \DateTime("now"));
$userprofile->__set('user', $this);
$em = $this->getEntityManager(); //doesn't work because getServiceLocator()->get('doctrine..') fails
$em->persist($userprofile);
$em->flush();
}