Documentation

Light-weight, fast, simple and powerful!
 

Differences

This shows you the differences between two versions of the page.

the_observer_system [2012-03-13 23:16]
jackie
the_observer_system [2014-08-17 00:41] (current)
mvdkleijn
Line 1: Line 1:
-====== The Observer System ====== +This information has been migrated to http://docs.wolfcms.org/
- +
-===== Introduction ===== +
- +
-Like many applications, Wolf CMS has an event/observer system. We call it the observer system because Observers [[observer_event_list|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: +
- +
-<code php> +
-Observer::observe('page_edit_after_save', 'my_simple_observer'); +
- +
-function my_simple_observer($page) { +
-    /* do what you want to do */ +
-   var_dump($page); +
-+
-</code> +
- +
-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. +
- +
-<code php> +
-Observer::notify('my_plugin_event', $somevar); +
-</code> +
- +
-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. +
- +
-{{wiki:page_edit_form_observers.jpg?600}} +
- +
-===== Observer - List of Events ===== +
- +
-Full [[observer_event_list|List of Events]] that can be used with Observers can be found under [[plugin_developer_documentation|Plugin Development]] (see sidebar). +
 
the_observer_system.txt · Last modified: 2014-08-17 00:41 by mvdkleijn
 
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