Home arrow PHP arrow Page 5 - Mach-II for PHP: A Preview

Event Handlers - PHP

Mach-II is a framework for organizing applications using standard OO techniques. This article will cover how to install, set up and configure a Mach-II application, and explore basic coding techniques.

  1. Mach-II for PHP: A Preview
  2. Installation
  3. Configuration
  4. Properties
  5. Event Handlers
  6. Basic Coding Techniques
  7. Creating Views
By: Mike Britton
Rating: starstarstarstarstar / 17
October 18, 2004

print this article



Let’s examine <event-handlers> in mach-ii.xml. As you already know, event-handlers are where you define the events triggered during a request. They describe the event names, and which views to associate with them.

 <!-- Main (landing page) -->
 <event-handler event="showMain" access="public">
  <event-arg name="page" value="Main" />  
  <view-page name="main" />
 <!-- Process a few form variables for demonstration purposes -->
 <event-handler event="processForm" access="public">
  <event-mapping event="success" mapping="showResults" />
  <event-mapping event="noSuccess" mapping="showMain" />
  <notify listener="processForm" method="validateForm" resultKey="GLOBALS['results']" />

 <!-- Display results of form processing -->
 <event-handler event="showResults" access="public">
  <event-arg name="page" value="Success" />
  <view-page name="results" /> 
 <event-handler event="exception">
  <event-arg name="page" value="Failure" />
  <view-page name="exception" />


Figure 5  mach-ii.xml <event-handlers>

Obviously our application needs to have a landing page. Since we named our default event showMain, we’ve defined a showMain event handler to receive that default event:

<!-- Landing Page -->
<event-handler event="showMain" access="public">
 <event-arg name="page" value="Main" />
<view-page name="main" />

Figure 6  Our landing page’s event-handler

Events can also be announced in <event-handler>, allowing very complex interactions between objects.

Inside <event-handler> is a node named <view-page>. This calls views defined in <page-views>. This is where display files are organized.

<!-- PAGE-VIEWS -->
 <page-view name="main" page="/views/main.php" />
 <page-view name="showResults" page="/views/showResults.php" />
 <page-view name="exceptionEvent" page="/views/exception.php" />

Figure 7  page-views node

You’ll find yourself coding very specific event-handlers for each specific type of request. Similar to coding a method in a PHP class, event-handlers should be as concise and reusable as possible. It’s important to factor in the needs of your application when determining the granularity of your event-handlers.

The event handler we just defined will communicate with a <listener> we’ve created (below).

<!-- LISTENERS -->
 <listener name="processForm" type="phpMachII.model.processForm">
  <invoker type="MachII.framework.invokers.ObjectEvent" />

Figure 8  Listeners node

>>> More PHP Articles          >>> More By Mike Britton

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: