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

Basic Coding Techniques - 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.

TABLE OF CONTENTS:
  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
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Creating Listeners

Key to understanding Mach-II is discovering how to access variables passed in an event. For Fusebox developers the technique will feel similar to referencing form variables in the attributes scope: the framework does the conversion of form and url variables to properties of a Mach-II event (Event).

In our demo we post a form and process the variables with a Mach-II listener class. This class is a regular PHP class that extends MachII.framework.Listener:

class phpMachII_model_processForm extends MachII_framework_Listener
{
 function configure() {} // Called automatically by framework
}

Figure 9  ./model/processForm.php ~ A listener class

These variables are accessed by the listener class by calling Event like this:

$event->getArg(‘username’);

Figure 10  Accessing a value in Event

Listener classes are called by the framework using the mappings defined in the type attribute of a <listener> node (fig. 8). A method is defined in the event handler and then passed to the listener. Mach-II locates the listener class in its directory and calls the desired method. Finally, the listener receives the Event object and processes the request.

class phpMachII_model_processForm extends MachII_framework_Listener
{
 // Called automatically
 function configure() {}
 
 function validateForm($event) {
 
  // Retrieves values posted in form
  $thisUN = $event->getArg('username');
  $thisPW = $event->getArg('password');
 
  if (isset($thisUN) && isset($thisPW) && $thisUN == "admin" && $thisPW == "machii") {
   $message = "Success";
   $this->announceEvent('success', $message);
  } else {   
   $message = "Failure";
   $this->announceEvent('noSuccess', $message);
  }
 
  return $message;
 }
 
}


Figure 11  ./model/processForm.php ~ accessing form variables from a listener by executing Event’s getArg method.



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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- 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: