AkObject | --AkObserver | --AkActsAsNestedSet
Located in File: /AkActiveRecord/AkActsAsBehaviours/AkActsAsNestedSet.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);
$_scope_condition (line 101)
* +parent_column+ - specifies the column name to use for keeping the position integer (default: parent_id) * +left_column+ - column name for left boundary data, default "lft" * +right_column+ - column name for right boundary data, default "rgt" * +scope+ - restricts what is to be considered a list. Example: <tt>actsAsList(array('scope' => array('todo_list_id = ? AND completed = 0',$todo_list_id)));</tt>
Constructor AkActsAsNestedSet (line 108)
Method addChild (line 250)
Method beforeCreate (line 396)
Method beforeDestroy (line 335)
Method countChildren (line 501)
Method getAllChildren (line 521)
Method getChildren (line 511)
Method getFullSet (line 555)
Method getLevel (line 486)
root level is 0
Method getParents (line 324)
Method getRoots (line 425)
Method getSelfAndAncestors (line 446)
Method getSelfAndSiblings (line 472)
Method getSiblings (line 460)
Method moveToChildOf (line 586)
Method moveToLeftOf (line 570)
Method moveToRightOf (line 578)
Method reloadActiveRecordInstance (line 143)
Method setLeftColumnName (line 193)
Method setParentColumnName (line 212)
Method setRightColumnName (line 202)
Method setScopeCondition (line 168)
Method _ensureIsActiveRecordInstance (line 123)
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() -