Scratching the Surface: Getting Started with PHP Fusebox - Almost There! (
Page 9 of 11 )
Now that both dsp_ pages are there
for either circuit, the fusebox should work, right? It will - as soon
as you add the XFA you just referenced in dsp_hello_world.php to the fbx_Switch.php in
/bio. Without reference to this XFA in your fbx_Switch.php
file, your PHP Fusebox application won't know what you're
talking about!
Open the fbx_Switch.php in /bio and
add the line in bold.
switch($Fusebox["fuseaction"]) {
case "main":
case "Fusebox.defaultFuseaction":
include("dsp_main.php");
break;
case "hello_world":
// Add this line:
$XFA["home"] = "home.main";
include("dsp_hello_world.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;
}
As soon as you do this, add an XFA link to the biography circuit in
the application root's dsp_main.php, and you'll be finished
with your first PHP Fusebox application!
<h3>Home: Main Page</h3>
This is the home page. Click the link below to
find out more about me.
<p>
<?
echo "<a href=\"$PHP_SELF?fuseaction=".$XFA["biography"]."\">Biography</a>";
?>
Now fire up a browser and surf to your application root. The default
fuseaction should be triggered automatically since you didn't type a fuseaction.
Mouse over the link to go to Biography. Notice
how the URL is now a real fuseaction and not an XFA? That's because
we defined the XFA in the application root's fbx_Switch.php file.
The Fusebox knows this XFA is a call to the application root's $Fusebox["circuits"]["biography"] circuit, which you
can see when you open fbx_Circuits.php in
the root:
$Fusebox["circuits"]["home"] =
"home";
$Fusebox["circuits"]["biography"]
= "home/bio";
Now click on the Biography link. The Biography pages comes up. Now click the Home link. You're back home. Continue doing
this for a few hours while listening to high-energy dance music!
If you think this might work for you, don't stop here. There are great
Fusebox-related sites all over the web. And Fusebox isn't just for PHP
- it was originally written for ColdFusion and is available for Java, as well.