Documentation

Light-weight, fast, simple and powerful!
Share This
Translations of this page?:

The Observer System

Introduction

Like many applications, Wolf CMS has an event/observer system. We call it the observer system because Observers watch for events. Most usually, the observers are used by plugins but they can be found in other parts of the Wolf CMS system.

Watching for events in a plugin

In your plugin’s index.php file add code similar to the following:

Observer::observe('page_edit_after_save', 'my_simple_observer');
 
function my_simple_observer($page) {
    /* do what you want to do */
   var_dump($page);
}

The first call to Observer::observe tells Wolf CMS that your plugin wants to receive events of the type 'page_edit_after_save' and that the function that should handle these types of events is called 'my_simple_observer'.

Generating an event

Since you can observe events that are generated, you can also generate events yourself.

Observer::notify('my_plugin_event', $somevar);

As you can see, the code to generate an event is fairly simple. The first argument, 'my_plugin_event', is the event's name. The second argument is a variable that is passed to the handling function. This variable can contain just about anything you want, from a simple string to an array of complex objects.

Using Observers to customize Page form

Observer events in the Page editing form allow you to include custom inputs or dialogs to save data that is not part of the page model.

This diagram is included to help you see which event you should use and where it would be applied in the form.

Page observer events

Observer - List of Events

Full List of Events that can be used with Observers can be found under Plugin Development (see sidebar).

 
the_observer_system.txt · Last modified: 2012-03-13 23:16 by jackie
 
Except where otherwise noted, content on this wiki is licensed under the following license:GNU Free Documentation License 1.2
Copyright 2010 wolfcms.org / design by yello studio / Wolf CMS Inside