Class AkObserver

(line 86)

Description

AkObject
   |
   --AkObserver

Located in File: /AkActiveRecord/AkObserver.php

Observer classes respond to life-cycle callbacks to implement trigger-like behavior outside the original class. This is a great way to reduce the clutter that normally comes when the model class is burdened with functionality that doesn't pertain to the core responsibility of the class.

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);



Classes extended from AkObserver:
AkActsAsNestedSet
Observer classes respond to life-cycle callbacks to implement trigger-like behavior outside the original class. This is a great way to reduce the clutter that normally comes when the model class is burdened with functionality that doesn't pertain to the core responsibility of the class.
AkActsAsTree
acts_as_tree
AkActsAsList
This act provides the capabilities for sorting and reordering a number of objects in list.
AkAssociation
Observer classes respond to life-cycle callbacks to implement trigger-like behavior outside the original class. This is a great way to reduce the clutter that normally comes when the model class is burdened with functionality that doesn't pertain to the core responsibility of the class.

Class Variables

Summary:
mixed $_observing

$_observing = array() (line 91)

Data type : mixed

$_observing array of models that we're observing

Class Constants

Summary:

Method Detail

Summary:
AkObserver __construct ()
void observe ($subject &$target)
void setObservedModels ($subject 0)
void update ([ $state = ''])

Constructor __construct (line 93)

AkObserver __construct( )

Overrides : AkObject::__construct() Class constructor, overriden in descendant classes

Info

Method observe (line 110)

void observe( $subject &$target)

Constructs the Observer

Parameters

  • $subject &$target: the name or names of the Models to observe

Info

Method setObservedModels (line 126)

void setObservedModels( $subject 0)

Constructs the Observer

Parameters

  • $subject 0: the name or names of the Models to observe

Info

Method update (line 146)

void update( [ $state = ''])

Parameters

  • $state:

Info

Inherited Variables

Inherited Class Variable Summary

Inherited Methods

Inherited Method Summary

Inherited From Class AkObject

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() -



Documentation generated on Tue, 17 Jun 2008 14:26:04 +0200 by phpDocumentor 1.3.2