Active Record Classes trigger Events via Symfony 1 Event Dispatcher
PHP
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
README.md
composer.json

README.md

sfPropelEventBehavior

Description

This behavior adds the ability to listen to lifecycle events in the Symfony 1.4 Event Dispatcher

Installation

composer.json

{
    "require": {
        "tschebel/sf-propel-event-behavior": "1.0.*"
    }
}

add following to your propel.ini file:

propel.behavior.sf_propel_event.class    = lib.vendor.sfPropelEventBehavior.lib.behavior.sfPropelEventBehavior

Enable the behavior in your config/schema.yml

_propel_behaviors:
  sf_propel_event:

Usage

Events are named by following schema: propel.[pre_insert|post_insert|pre_update|post_update|pre_save|post_save|pre_delete|post_delete].ModelName

Other than real lifecycle hooks in the model class a listener to a pre event cannot abort the save/delete action. If needed you may throw an exception and catch it

Connect your listener class in the Symfony Event Dispatcher.

$event_dispatcher->connect('propel.pre_save.CmsArticle', array('ArticleListener', 'preSave'));

Create your listener class

class ArticleListener
{
    static public function preSave(sfPropelEvent $event)
    {
        //the related article object
        $subject = $event->getSubject();

        //the related PropelPDO connection
        $con = $event->getConnection();
    }
}