Search code examples
symfonyentityafter-save

What is the Symfony2 equivalent to CakePHP beforeSave() afterSave()?


I would like to save notifications after certain events in my Symfony2 app. I've created a Notification Entity but I'm not sure how I can trigger an aftersave event on some other Entity to create a new Notification record.

In CakePHP I would add something like this to the other Model

function afterSave( )
{
    App::import( 'Model', 'Notification' );
    $Notification = new Notification;

    $notification = array( 'Notification' => array(
        'person_id' => Person::get( 'Person.id' ),
        'type' => 'foo',
        'title' => 'bar',
        'details' => 'lorem ipsum'
    ) );

    $Notification->save( $notification );
}

Solution

  • Definitely, take a look at Doctrine events - http://symfony.com/doc/current/cookbook/doctrine/event_listeners_subscribers.html