symfony - can't pass argument to event listener -
using symfony 2.5.3. i'm trying send 'welcome' e-mail when has succesfully registered(fos userbunde), using eventlistener. event fired fos_user.registration.success
.
so added service:
mycustom_user.registration_success: class: mycustom\userbundle\eventlistener\registrationlistener arguments: [@mycustom_user.mailer] tags: - { name: kernel.event_listener, event: fos_user_registration_success, method: onregistrationsuccess}
the listener itself:
namespace mycustom\userbundle\eventlistener; use fos\userbundle\fosuserevents; use fos\userbundle\event\userevent; use fos\userbundle\event\formevent; use mycustom\userbundle\mailer\mailer; use symfony\component\eventdispatcher\eventsubscriberinterface; class registrationlistener implements eventsubscriberinterface { protected $mailer; public function __construct(mailer $mailer) { $this->mailer = $mailer; } public static function getsubscribedevents() { return array( fosuserevents::registration_success => 'onregistrationsuccess', ); } public function onregistrationsuccess(formevent $event) { $user = $event->getform()->getdata(); $this->mailer->sendwelcomemessage($user); $url = $this->router->generate('fos_user_security_login'); $event->setresponse(new redirectresponse($url)); } }
the mailer contains rendering of content of email, registered service:
mycustom_user.mailer: class: mycustom\userbundle\mailer\mailer arguments: ['@templating']
mycustom_user.mailer
argument listener. somehow keep getting error:
catchable fatal error: argument 1 passed mycustom\userbundle\eventlistener\registrationlistener::__construct() must instance of mycustom\userbundle\mailer\mailer, none given, called in mycustom/app/cache/dev/appdevdebugprojectcontainer.php on line 2214 , defined in mycustom/src/mycustom/userbundle/eventlistener/registrationlistener.php line 19
i tried other arguments @doctrine (and changed listeners constructor accordingly), keep getting same error. @templating argument mailer service doesn't work.
what doing wrong here?
so, problem had had 2 listeners in 1 class. , 2nd service definition didn't contain argument constructor. should this:
mycustom_user.registration_initialize: class: mycustom\userbundle\eventlistener\registrationlistener arguments: ['@mycustom_user.mailer'] tags: - { name: kernel.event_subscriber, alias: mycustom_user_registration_listener} mycustom_user.registration_success: class: mycustom\userbundle\eventlistener\registrationlistener arguments: ['@mycustom_user.mailer'] tags: - { name: kernel.event_subscriber }
Comments
Post a Comment