AkObject | --AkObserver | --AkAssociation
Located in File: /AkActiveRecord/AkAssociation.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);
Method addAssociated (line 151)
Overridden in child classes as:
Method addModel (line 90)
Method getAssociatedFinderSqlOptions (line 161)
Overridden in child classes as:
Method getOption (line 85)
Method initializeAssociated (line 34)
Method loadAssociated (line 133)
Method setAssociatedId (line 127)
Method setAssociationId (line 53)
Method setOptions (line 75)
Method _build (line 113)
Overridden in child classes as:
Method _findOwnerTypeForAssociation (line 190)
Method _getLoadedHandler (line 182)
Method _hasTablePrefix (line 172)
Method _saveLoadedHandler (line 177)
Method _setAssociationAccesorAliasReferences (line 67)
AkObserver::$_observing - $_observing array of models that we're observing
AkObserver::__construct() -
AkObserver::observe() - Constructs the Observer
AkObserver::setObservedModels() - Constructs the Observer
AkObserver::update() -
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() -