AkObject | --AkObserver
Located in File: /AkActiveRecord/AkObserver.php
Example:
class CommentObserver extends AkObserver { function afterSave($comment) { Ak::mail("admin@example.com", "New comment was posted", $comment->toString()); } }
This Observer sends an email when a Comment::save is finished.
## Observing a class that can't be inferred
Observers will by default be mapped to the class with which they share a name. So CommentObserver will be tied to observing Comment, ProductManagerObserver to ProductManager, and so on. If you want to name your observer differently than the class you're interested in observing, you can use the AkActiveRecord->observe() class method:
function afterUpdate(&$account) { $AuditTrail =& new AuditTrail($account, "UPDATED"); $AuditTrail->save(); }
If the audit observer needs to watch more than one kind of object, this can be specified with multiple arguments:
function afterUpdate(&$record) { $ObservedRecord =& new AuditTrail($record, "UPDATED"); $ObservedRecord->save(); }
The AuditObserver will now act on both updates to Account and Balance by treating them both as records.
## Available callback methods
The observer can implement callback methods for each of these methods: beforeCreate, beforeValidation, beforeValidationOnCreate, beforeSave, afterValidation, afterValidationOnCreate, afterCreate and afterSave
## Triggering Observers
In order to activate an observer, you need to call create an Observer instance and attach it to a model.
In the Akelos Framework, this can be done in controllers using the short-hand of for example:
$ComentObserverInstance =& new CommentObserver(); $Model->addObserver(&$ComentObserverInstance);
Constructor __construct (line 93)
Overrides : AkObject::__construct() Class constructor, overriden in descendant classes
Method observe (line 110)
Method setObservedModels (line 126)
AkObject::AkObject() - A hack to support __construct() on PHP 4
AkObject::__construct() - Class constructor, overriden in descendant classes
AkObject::freeMemory() - Unsets circular reference children that are not freed from memory when calling unset() or when the parent object is garbage collected.
AkObject::log() -
AkObject::toString() - Object-to-string conversion
AkObject::__clone() - Clone class (Zend Engine 2 compatibility trick)
AkObject::__destruct() - Class destructor, overriden in descendant classes
AkObject::__toString() -