我正在使用FosUserBundle,我想挂钩到控制器来做自定义的东西,所以我使用FOSUserEvents但我不能让它工作。 事实上,我的事件根本没有被触发,我无法弄清楚它为什么不是。
我已经要求" friendsofsymfony / user-bundle":" 2.0。* @ dev"在我的composer.json中,并遵循FOS github(FOSUserEvents hook into the controller)的例子
我想念一下吗?
这是我的配置/代码......:
<?php
namespace Om\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;
class ProfileRegisterListener implements EventSubscriberInterface {
private $router;
public function __construct(UrlGeneratorInterface $router) {
$this->router = $router;
die('construct ProfileRegisterListener');
}
/**
* {@inheritDoc}
*/
public static function getSubscribedEvents() {
return array(
FOSUserEvents::REGISTRATION_INITIALIZE => 'onRegisterSuccess',
FOSUserEvents::REGISTRATION_SUCCESS => 'onRegisterSuccess',
FOSUserEvents::REGISTRATION_CONFIRM => 'onRegisterSuccess',
FOSUserEvents::REGISTRATION_CONFIRMED => 'onRegisterSuccess',
FOSUserEvents::REGISTRATION_COMPLETED => 'onRegisterSuccess',
);
}
public function onRegisterSuccess(FormEvent $event) {
$url = $this->router->generate('/');
die('i die onRegisterSuccess');
$event->setResponse(new RedirectResponse($url));
}
}
我的userbundle中的和我的service.yml:
services:
om_user_registration.form.type:
class: Om\UserBundle\Form\Type\RegistrationFormType
tags:
- { name: form.type, alias: om_userbundle_registration}
om_user.register_profile:
class: Om\UserBundle\EventListener\ProfileRegisterListener
arguments: [@router]
tags:
- { name: Kernel.event_subscriber}
在我的app config.yml
中fos_user:
db_driver: orm
firewall_name: main
user_class: Om\UserBundle\Entity\User
use_listener: true
registration:
form:
type: om_userbundle_registration
我的security.yml
security:
encoders:
FOS\UserBundle\Model\UserInterface: sha512
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
fos_userbundle:
id: fos_user.user_provider.username_email
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
login_path: /login
check_path: /login_check
default_target_path: /profile
# oauth:
# resource_owners:
# facebook: "/login/check-facebook"
# login_path: /login
# failure_path: /login
#
# oauth_user_provider:
# service: user_provider
logout: true
anonymous: true
login:
pattern: ^/login$
security: false
remember_me:
key: "%secret%"
lifetime: 31536000 # 365 days in seconds
path: /
domain: ~ # Defaults to the current domain from $_SERVER
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
答案 0 :(得分:0)
试试这个:
public static function getSubscribedEvents() {
return array(
FOSUserEvents::REGISTRATION_SUCCESS => 'onRegisterSuccess'
);
}
它仅适用于REGISTRATION_SUCCESS事件。如果您搜索FOSUserEvent。 PHP你可以找到每个事件的目的。
答案 1 :(得分:0)
我知道这是旧的,但遇到同样的问题,您的FOSUserBundle电子邮件选项不已启用。
如果您未激活配置中的电子邮件,那么听众就不会被触发
>>> df.show()
+---+---+
|aid|bid|
+---+---+
| 1| 1|
| 1| 2|
| 1| 3|
| 2| 10|
| 2| 12|
+---+---+
>>> checkList = [(1,2),(2,12),(1,100)]
>>> df.rdd.filter(lambda (x,y): (x,y) in checkList).toDF().show()
+---+---+
|aid|bid|
+---+---+
| 1| 2|
| 2| 12|
+---+---+
文档:https://symfony.com/doc/current/bundles/FOSUserBundle/emails.html#registration-confirmation