Home arrow PHP arrow Page 7 - Scratching the Surface: Getting Started with PHP Fusebox

Using XFAs - PHP

Originally designed for ColdFusion, Fusebox is a methodology for designing web-applications with extensibility and ease of maintenance that is now available for PHP.

  1. Scratching the Surface: Getting Started with PHP Fusebox
  2. Step 1: Setting Up the Core Files
  3. What do the "core files" do?
  4. A Word on FuseDocs
  5. Fusebox Naming Conventions
  6. Picking Up Where We Left Off: Setting Up the Core Files
  7. Using XFAs
  8. Step 2: Creating the "Biography" Circuit
  9. Almost There!
  10. PHP-Fusebox Links
  11. Fusebox Links
By: Mike Britton
Rating: starstarstarstarstar / 8
May 29, 2002

print this article



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";




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



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"]."\">


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

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: