com>
Please post comments or corrections to the Author Online forum at
http://www.manning-sandbox.com/forum.jspa?forumID=329
}
}
A Array of registered observers
1 Ensure that observer contains a function called observeTableRow()
2 Add the observer to the list if it??™s not already there.
The first two functions we need are the core of the Observer pattern. The attachObserver() function
is used to allow an observer to attach itself. We use a static function as the list of observers because the list of
observers is independent of a specific model class. Similarly, the array of observers is static as it needs to be
accessible from every model class.
The notifyObservers() function is used to notify all observers that have been attached to the class.
This function simply iteratates over the list and calls a static function, observerTableRow() within the
observer class. The observer can then use the information about what the event is and the data from the model
to perform whatever action is necessary. In this case, we will update the search index.
Zend_Db_Table_Row_Abstract provides a number of hook functions that allow us to perform processing
before and after the database row is inserted, updated or deleted. We use those functions to call
notifyObservers(); the ones we need for updating the search index are _postInsert(), _postUpdate() and
_postDelete().
Pages:
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231