Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register event needs to be changed to after persist #5

Closed
danrossi opened this issue Jan 17, 2012 · 5 comments
Closed

Register event needs to be changed to after persist #5

danrossi opened this issue Jan 17, 2012 · 5 comments

Comments

@danrossi
Copy link

I am able to get a listener working for the register event but it needs to be moved to after persist to get the modified user document with the id so further details can be added to it.

http://dl.dropbox.com/u/3394987/ZfcUser.diff

If there is a better way to supply diffs in github I'm all ears .

@danrossi
Copy link
Author

I can now listen for the event and make updates to the user document to add some extra embedded profile documents to the user.

$events->attach('ZfcUser\Service\User', 'createFromForm', function($e) use ($config, $app) {

            $form = $app->getLocator()->get('custom_register_form');

            $params = $e->getParams();
            $form->update($params["user"]);

});

...

public function update($user)
{
    $player = new Player();

    $user->player = $player;

    $this->dm->persist($user);
    $this->dm->flush();

}

@EvanDotPro
Copy link
Member

For diffs, you can send a pull request instead of hosting the diff yourself.

@EvanDotPro
Copy link
Member

You're absolutely right that an event should be fired after registration with the modified user object (with the ID populated). I'll try to get this in soon.

@adamlundrigan
Copy link
Contributor

I've submitted a PR (#101) which takes care of this issue. It adds a register.post event which triggers after the entity has persisted. The original event, register, is left intact for BC.

@EvanDotPro
Copy link
Member

Thanks @adamlundrigan!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants