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

Picking Up Where We Left Off: Setting Up the Core Files - 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



Now that we've copied the core files into the root directory, let's go ahead and create a simple circuit app that demonstrates the basic principles behind the PHP Fusebox architecture.

1. Open fbx_Circuits.php.  You'll see the fusedoc XML at the top, followed by the default home circuit definition:

$Fusebox["circuits"]["home"] = "home";

This code is identifying the $Fusebox["circuits"]["home"] nested array element as "home".  The lack of slash mark(s) in the value in quotation marks tells us this circuit is in the root directory.

When the $Fusebox["circuits"] structure is passed, fuseaction=home.main in the URL for instance, the application will know this circuit is in the application root, and the core "engine" file, fbx_Fusebox3.0_PHP4.1.x.php, will include the application root's  fbx_Switch.php to complete the request.

Note: Although it isn't explicitly required to create PHP Fusebox 3 web sites, you can see how all this works by opening the "engine" file we discussed earlier, fbx_Fusebox3.0_PHP4.1.x.php.  Checking under the hood of this file is advisable.  The code is well commented with in-line comments and FuseDocs.

Ordinarily, if we were constructing a complex web application with PHP Fusebox, we'd add additional code to define more circuits in the application root's fbx_Circuits.php:

$Fusebox["circuits"]["sectionOne"] = "home/sectionOne";

$Fusebox["circuits"]["sectionTwo"] = "home/sectionTwo";

There could be as many circuits as you want.  For our purposes, we'll only be working with two circuits: the "home" and "biography" circuits.  Change the code of fbx_Circuits.php to read:

$Fusebox["circuits"]["home"] = "home";

$Fusebox["circuits"]["biography"] = "home/bio";

The circuit you have just defined below the "home" circuit could be accessed through either the URL or some kind of form action (POST or GET).  For our purposes, we'll be calling our circuits through simple text links.

2. In the root directory of your application, open fbx_Switch.php.  This is where you'll define all the fuses in this, the home (or root) circuit.  Like I said before, you'll be using the switch / case statement in this file to include files based on the fuseaction passed to the application.

The default code looks like this:

switch($Fusebox["fuseaction"]) {

      case "main":

      case "Fusebox.defaultFuseaction":




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



The switch statement switch($Fusebox["fuseaction"]) receives the $Fusebox["fuseaction"] variable from the URL, a form - whatever you want to use to pass it - and passes the fuseaction down through the case statements until it finds one that matches.  When a match is encountered, the matching case statement specifies which files are included.  In this situation, if the "main" fuseaction were specified, the file dsp_main.php would be included.  If no fuseaction were passed, the same file would be included because the default case statement calls the same fuse.

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