저는 도움을 요청하는 데 익숙하지 않지만,이 문제에 대해서는 스스로 해결할 수 없다고 고백합니다.symfony의 서비스를 통해 이전 서버를 보내는 방법
동일한 양식 (loginform 및 fosuserbundle의 등록 양식)에 2 개의 양식이 있습니다. 두 양식 모두 작동합니다.
기존 사용자가 가입하려고하면 내 문제가 발생합니다.
전자 메일이 이미있는 경우 동일한 페이지에서 사용자를 리디렉션하는 RegistrationFailureListener
을 생성했습니다.
그러나이 양식에는 register/
경로에 표시되는 오류가 표시되지 않습니다.
내 양식에 이러한 양식 오류를 보내는 방법을 모르겠습니다.
죄송합니다.
내 코드 :
<?php
namespace TNS\UserBundle\EventListener;
use FOS\UserBundle\Event\FormEvent;
use FOS\UserBundle\FOSUserEvents;
use FOS\UserBundle\Mailer\MailerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Csrf\TokenGenerator\TokenGeneratorInterface;
class RegistrationListener implements EventSubscriberInterface
{
/**
* @var UrlGeneratorInterface
*/
private $router;
/**
* @var TokenGeneratorInterface
*/
private $tokenGenerator;
/**
* @var SessionInterface
*/
private $session;
/**
* @var MailerInterface
*/
private $mailer;
/**
* RegistrationSuccessListener constructor.
* @param UrlGeneratorInterface $router
* @param TokenGeneratorInterface $tokenGenerator
* @param SessionInterface $session
* @param MailerInterface $mailer
*/
public function __construct(UrlGeneratorInterface $router, TokenGeneratorInterface $tokenGenerator, SessionInterface $session, MailerInterface $mailer)
{
$this->router = $router;
$this->tokenGenerator = $tokenGenerator;
$this->session = $session;
$this->mailer = $mailer;
}
/**
* Returns an array of event names this subscriber wants to listen to.
*
* The array keys are event names and the value can be:
*
* * The method name to call (priority defaults to 0)
* * An array composed of the method name to call and the priority
* * An array of arrays composed of the method names to call and respective
* priorities, or 0 if unset
*
* For instance:
*
* * array('eventName' => 'methodName')
* * array('eventName' => array('methodName', $priority))
* * array('eventName' => array(array('methodName1', $priority), array('methodName2')))
*
* @return array The event names to listen to
*/
public static function getSubscribedEvents()
{
return array(
FOSUserEvents::REGISTRATION_SUCCESS => 'onRegistrationSuccess',
FOSUserEvents::REGISTRATION_FAILURE => 'onRegistrationFailure'
);
}
public function onRegistrationFailure(FormEvent $event) {
$url = $this->router->generate('tns_core_homepage');
$event->setResponse(new RedirectResponse($url));
}
public function onRegistrationSuccess(FormEvent $event)
{
/** @var $user \FOS\UserBundle\Model\UserInterface */
$user = $event->getForm()->getData();
$user->setEnabled(false);
if (null === $user->getConfirmationToken()) {
$user->setConfirmationToken($this->tokenGenerator->generateToken());
}
$this->session->set('fos_user_send_confirmation_email/email', $user->getEmail());
$url = $this->router->generate('fos_user_registration_check_email');
$event->setResponse(new RedirectResponse($url));
}
}
내 RegisterController이
이 대답은 여기에 리디렉션 대신 템플릿을 렌더링하기 위해 제안 ..... 다른 사람을 도울 수 있다면 - https://stackoverflow.com/questions/17269844/symfony-2-separate-form- logic-show-form-errors-after-redirect – Bananaapple
괜찮 았어, 나는 내 서비스에 템플릿을 삽입하려고했는데 이제는 리다이렉트 대신 렌더링을한다. 하지만 이제는 커스텀 페이지 대신에 레지스터/경로로 방향이 바뀌었고 원하는 바가 아니 었습니다. 내 서비스에 templating을 주입하는 방법을 배웠습니다. –
registercontroller에서 내 등록 작업이 끝날 때 렌더링을 변경합니까? –