Prev | Current Page 220 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"

Each function is the same as _postInsert() is shown in Listing 8.5.
Listing 8.4: Notifying the observer after an insert
class Places_Db_Table_Row_Observerable extends Zend_Db_Table_Row_Abstract
{
protected function _postInsert()
{
self::notifyObservers('post-insert'); A
}
}
A Pass the event type to the observer as a string
Let??™s look now at the observer class. This class is called SearchIndexer and, as it is a model, is stored in
application/models. The code to register it with the observerable class is in the bootstrap and and looks like
this:
SearchIndexer::setIndexDirectory(ROOT_DIR . '/var/search_index');
Places_Db_Table_Row_Observerable::attachObserver('SearchIndexer');
As you can see, it??™s simply a case of setting the directory to store the search index files and then attaching
the class to the Places_Db_Table_Row_Observerable using the name of the class. There are three main
functions in SearchIndexer and these are shown in Listings 8.5, 8.6 and 8.7.
Listing 8.5: SearchIndexer::observeTableRow(): the notification hook function
class SearchIndexer
{
public static function observeTableRow($event, $row)
{
switch ($event) {
case 'post-insert': A
case 'post-update': A
$doc = self::getDocument($row); 1
if ($doc !== false) {
self::_addToIndex($doc); 2
}
break;
}
Licensed to Menshu You

Pages:
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
opony goodyear olej manuka nobel calling cards zakłady bukmacherskie uchwyt lcd