-2
我試圖讓「註冊確認」我的應用程序的工作,但不能。因爲我需要設置配置文件等等,這是我的用戶的方法save
如何某些字段:無法獲取「註冊確認」工作在FOSUserBundle在我自己的函數
公共職能saveAction(請求$要求) {$ EM = $這個 - > getDoctrine() - > getManager ();
/** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */
$userManager = $this->container->get('fos_user.user_manager');
/** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */
$dispatcher = $this->container->get('event_dispatcher');
$user = $userManager->createUser();
$event = new GetResponseUserEvent($user, $request);
$dispatcher->dispatch(FOSUserEvents::REGISTRATION_INITIALIZE, $event);
if (null !== $event->getResponse()) {
return $event->getResponse();
}
$entityProfile = new SysPerfil();
$formProfile = $this->createForm(new PerfilType(), $entityProfile);
$formProfile->handleRequest($request);
$user_data = $request->get('user_profile');
if ($formProfile->isValid()) {
$event = new FormEvent($formProfile, $request);
$dispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS, $event);
$role = $request->get('user_profile')['roleType'];
$user->setUsername($user_data['rif']);
$user->setEmail($user_data['user']['email']);
$user->setPlainPassword($user_data['user']['password']);
if ($role === "O") {
$user->addRole("ROLE_OPERADOR");
}
elseif ($role === "CH") {
$user->addRole("ROLE_CENTRO_HIPICO");
}
$userManager->updateUser($user);
$entityProfile->setUser($user);
$em->persist($entityProfile);
$em->flush();
$dispatcher->dispatch(FOSUserEvents::REGISTRATION_COMPLETED, new FilterUserResponseEvent($user, $request));
return $this->redirect($this->generateUrl('login'));
}
else {
$errors = $this->getFormErrors($formProfile);
}
return new JsonResponse(array('status' => true, 'errors' => $errors));
}
而這正是我在config.yml
文件中配置:
# FOSUserBundle
fos_user:
db_driver: orm
firewall_name: main
user_class: Sunahip\UserBundle\Entity\SysUsuario
group:
group_class: Sunahip\UserBundle\Entity\SysGrupos
registration:
confirmation:
enabled: true
但我發現了這個錯誤:
Attempted to call method "setEnabled" on class "UserBundle\Entity\SysPerfil" in /var/www /html/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/EventListener /EmailConfirmationListener.php line 50.
我做了什麼錯?