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'));
}
}
One Comment
There’s also preInsert(), postInsert(), preUpdate() and postUpdate() methods that can be usefull…