PHP
  Home arrow PHP arrow Page 6 - Mach-II for PHP: A Preview
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Mach-II for PHP: A Preview
By: Mike Britton
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 17
    2004-10-18


    Table of Contents:
  • Mach-II for PHP: A Preview
  • Installation
  • Configuration
  • Properties
  • Event Handlers
  • Basic Coding Techniques
  • Creating Views

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Mach-II for PHP: A Preview - Basic Coding Techniques
    ( Page 6 of 7 )

    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
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    Stay green...Green IT