Symfony, Doctrine, preSave and postSave

My new Symfony app calls a remote web service as part of the user creation process. Since this is intimately linked with the model (I want this behavior executed for my fixtures, too) it makes no sense to call the web service from the controller.

Like Ruby on Rails, Doctrine has some handy built-in hooks to execute code before and after saving a record. Here’s what my updated model looks like:

class sfGuardUser extends PluginsfGuardUser {
 public function preSave($obj){
  some_voodoo_magic($this->get('id'));
 }

 public function postSave($obj){
  call_my_special_webservice($this->get('id'));
 }

}

This entry was posted in Technology. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

One Comment

  1. Gregoire
    Posted June 10, 2009 at 1:18 am | Permalink

    There’s also preInsert(), postInsert(), preUpdate() and postUpdate() methods that can be usefull… ;)

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>