Все методы получают как параметр объект класса Doctrine_Event.
Список доступных методов слушателей:
Методы | Слушают | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
preSave() | save() | |||||||||||||
postSave() | save() | |||||||||||||
preUpdate() | save() when the record state is DIRTY | |||||||||||||
postUpdate() | save() when the record state is DIRTY | |||||||||||||
preInsert() | save() when the record state is TDIRTY | |||||||||||||
postInsert() | save() when the record state is TDIRTY | |||||||||||||
preDelete() | delete() | |||||||||||||
postDelete() | delete() | |||||||||||||
preValidate() | validate() | |||||||||||||
postValidate() | validate() |
Пример:
class Debugger extends Doctrine_Record_Listener {
public function postDelete(Doctrine_Event $event) {
echo 'deleted ' . $event->getInvoker()->id;
}
}
// Добавление слушателя так ...
class MyRecord extends Doctrine_Record {
// ...
public function setUp() {
$this->addListener(new Debugger());
}
}
// ... или так
$myRecord = new MyRecord();
$myRecord->addListener(new Debugger());
Комментариев нет:
Отправить комментарий