PHP
  Home arrow PHP arrow Page 7 - Scratching the Surface: Getting Started with PHP Fusebox
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

Scratching the Surface: Getting Started with PHP Fusebox
By: Mike Britton
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 8
    2002-05-29


    Table of Contents:
  • Scratching the Surface: Getting Started with PHP Fusebox
  • Step 1: Setting Up the Core Files
  • What do the "core files" do?
  • A Word on FuseDocs
  • Fusebox Naming Conventions
  • Picking Up Where We Left Off: Setting Up the Core Files
  • Using XFAs
  • Step 2: Creating the "Biography" Circuit
  • Almost There!
  • PHP-Fusebox Links
  • Fusebox Links

  • 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


    Scratching the Surface: Getting Started with PHP Fusebox - Using XFAs
    ( Page 7 of 11 )

    Let's say you want one screen on your web site to lead into another, like in a traditional login system where the user types his / her username and password into a text field and presses the submit button.  In Fusebox, instead of hard-coding a path to a CGI script or another PHP page in your form's "action" parameter, you simply specify an exit fuseaction, or XFA

    What's an XFA?

    PHP Fusebox filenames must begin with either dsp_, act_, url_, or qry_.  They contain exit fuseactions that are picked up in a circuit's fbx_Switch.php file.

    For example, one of your circuits' dynamically-included files will contain references collectively known as XFAs.  When called, these XFAs communicate with the switch/case statement in fbx_Switch.php, telling it to find a matching circuit (case statement), and an XFA definition inside the case statement, one that tells the application where the exit for that fuseaction is.  It helps to remember "X for exit".

    To further illustrate, let's focus again on fbx_Switch.php.  Add the following code under the initial case statements:

    $XFA["biography"] = "biography.hello_world";

    Now your switch statement should look like this:

    switch($Fusebox["fuseaction"]) {

          case "main":

          case "Fusebox.defaultFuseaction":

    // Add this line:

    $XFA["biography"] = "biography.hello_world";

                include("dsp_main.php");

                break;

          default:

                print "I received a fuseaction called <b>'" . $Fusebox["fuseaction"] . "'</b> that circuit <b>'" . $Fusebox["circuit"] . "'</b> does not have a handler for.";

                break;

    }

    This may take a while to get right in your head.  While fbx_Switch.php dynamically includes files, it also controls the flow of the application.  Think of it as a railroad switch that directs your model train by moving the switch to the correct track.  Your train signals the switch where it wants to go, and the switch moves into place to match the signal sent by the train.  What you've just done is instruct the circuit to go to the bio/ directory (or "biography" circuit if you think about it from the perspective of the application root's fbx_Circuits.php file) when passed an XFA called "biography".  The biography circuit's fbx_Switch.php will have a case statement that looks for the fuseaction "hello_world" and include the files you define for this circuit.

    But wait, we're getting ahead of ourselves.  Deeeep breath.  First, we have to understand how these XFAs are passed in the context of the application.

    An XFA or exit fuseaction called from a URL:

    <a href=\"$PHP_SELF?fuseaction=".$XFA["biography"]."\">Example Link</a>

    An XFA or exit fuseaction called from form POST:

    <form action=\"$PHP_SELF?fuseaction=".$XFA["biography"]."\" method=\"post\">

    Or a GET:

    <form action=\"$PHP_SELF\">

    <input type=\"hidden\" name=\"fuseaction\" value=\"".$XFA["biography"]."\">

    </form>

    The beauty of PHP Fusebox is in the abstraction of the file system's real structure: using XFAs, you can send the application to any circuit (directory) you want, and have it perform whatever duties you wish.  As long as the root directory's fbx_Circuits.php contains a matching circuit definition and its fbx_Switch.php contains a corresponding XFA that can tell fbx_Circuits.php where to go next, the sky's the limit!



     
     
    >>> 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 2 Hosted by Hostway
    Stay green...Green IT