Difference between revisions of "JEvent"
From Joomla! Documentation
(New page: <span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>Edit Descripton<nowiki>]</nowiki>
</span>
{{Description:JEvent}}
===Defined in===
librari...) |
m (preparing for archive only) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | + | JEvent is a an abstract class for the definition of event handlers. Together with the JDispatcher class, it implements the base functionality for the Event-Dispatcher design pattern. JEvent needs to be extended by a concrete event handler class, that implements the functionality that will be triggered once an event occurs. | |
− | + | ||
− | + | ===The Event-Dispatcher-Pattern=== | |
− | + | The Joomla Framework is divided into different tiers (See: [[Framework]]). The idea is that business logic and information of one part of the application are encapsulated, so they can be changed, and replaced without affecting other parts of the application. Sometimes however, you need to access information from other parts of the application. The Registry pattern can help you with that (See: JRegistry). And sometimes you want other parts of the application to be automatically informed, once an event ''anywhere'' within the application occurs. This is where the Event-Dispatcher-Pattern comes into play. | |
+ | |||
+ | The pattern allows you to register event-handlers for a certain event at a global event-dispatcher. Once the event occures, the event-dispatcher calls all event-handlers that handle that certain event and passes a set of arguments to it. | ||
===Defined in=== | ===Defined in=== | ||
Line 19: | Line 21: | ||
<source lang="php">jimport( 'joomla.event.event' );</source> | <source lang="php">jimport( 'joomla.event.event' );</source> | ||
− | + | ||
− | + | ||
− | |||
− | |||
===Examples=== | ===Examples=== | ||
− | + | === Code Examples === | |
<dpl> | <dpl> | ||
noresultsheader=\n | noresultsheader=\n | ||
+ | namespace=CodeExample | ||
category=JEvent | category=JEvent | ||
− | + | namespace=CodeExample | |
category=ClassExample | category=ClassExample | ||
include=* | include=* | ||
format= ,,, | format= ,,, | ||
</dpl> | </dpl> |
Latest revision as of 20:37, 24 March 2017
The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.
JEvent is a an abstract class for the definition of event handlers. Together with the JDispatcher class, it implements the base functionality for the Event-Dispatcher design pattern. JEvent needs to be extended by a concrete event handler class, that implements the functionality that will be triggered once an event occurs.
The Event-Dispatcher-Pattern[edit]
The Joomla Framework is divided into different tiers (See: Framework). The idea is that business logic and information of one part of the application are encapsulated, so they can be changed, and replaced without affecting other parts of the application. Sometimes however, you need to access information from other parts of the application. The Registry pattern can help you with that (See: JRegistry). And sometimes you want other parts of the application to be automatically informed, once an event anywhere within the application occurs. This is where the Event-Dispatcher-Pattern comes into play.
The pattern allows you to register event-handlers for a certain event at a global event-dispatcher. Once the event occures, the event-dispatcher calls all event-handlers that handle that certain event and passes a set of arguments to it.
Defined in[edit]
libraries/joomla/event/event.php
Methods[edit]
Method name | Description |
---|---|
update | Method to trigger events. |
Importing[edit]
jimport( 'joomla.event.event' );
Let's think of an event, that could affect different parts of your application... To keep it simple, we say that we create an onEmailChange event, that is triggered once the user changes his email address. When he does that, we want to display the change to the screen, but we also want to store it to the database. We also know, that there might be some components out there, who would like to implement their own functionality, once the useer changes his email-address.
After the Event Handlers have been created and added to the dispatcher, the event can be triggered from anywhere in the application. This could be in another module, another component, within the framework or even in another plugin.
Other components can now create their own concrete Event Handlers for the onEmailChange event and register it to the dispatcher. They will automatically be triggered once the event occurs anywhere in the application.
This example was originally contributed by User:Batch1211.