【发布时间】:2014-04-24 09:10:21
【问题描述】:
1) 如何在表格和注册操作中添加新字段(在注册页面上显示新字段)?例如:我想添加新字段last_name、age。
2) 我为 REGISTRATION_COMPLETED 添加了新的监听器
/src/Acme/UserBundle/EventListener/RegistrationCompletedListener.php:
<?php
namespace Acme\UserBundle\EventListener;
use FOS\UserBundle\FOSUserEvents;
use FOS\UserBundle\Event\FormEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
/**
* Listener
*/
class RegistrationCompletedListener implements EventSubscriberInterface
{
private $router;
public function __construct(UrlGeneratorInterface $router)
{
$this->router = $router;
}
/**
* {@inheritDoc}
*/
public static function getSubscribedEvents()
{
return array(
FOSUserEvents::REGISTRATION_COMPLETED => 'onRegistrationCompletedSuccess',
);
}
public function onRegistrationCompletedSuccess(FormEvent $event)
{
$url = $this->router->generate('homepage');
$event->setResponse(new RedirectResponse($url));
}
}
/src/Acme/UserBundle/Resources/config/services.yml:
services:
acme_user.registration_completed:
class: Acme\UserBundle\EventListener\RegistrationCompletedListener
arguments: [@router]
tags:
- { name: kernel.event_subscriber }
为什么不工作?
【问题讨论】:
-
FormEvent没有方法setResponse -
公共函数 onRegistrationCompletedSuccess() { echo 1;出口; } 不要工作太... :(
-
您应该创建两个问题。回答起来会容易得多。
标签: php symfony fosuserbundle