Scratching the Surface: Getting Started with PHP Fusebox - Step 2: Creating the "Biography" Circuit
(Page 8 of 11 )
You've added code that references the biography circuit, so now it's time to create it! In your application root (the one you're calling "home" in fbx_Circuits.php), create another directory and call it bio. This is where we're going to build the biography circuit.
Now you must copy the following PHP Fusebox core files into the bio directory (it's a subset of the same files found in your application root):
DefaultLayout.php
dsp_main.php
fbx_SaveContent.php
fbx_Settings.php
fbx_Switch.php
index.php
See, there's fbx_Switch.php again! The biography circuit's fbx_Switch.php will include the files needed to satisfy the fuseactions passed to it, as we've already discussed.
Open the /bio directory's fbx_Switch.php.
You will see similar code to the fbx_Switch.php we already edited, in the application root:
switch($Fusebox["fuseaction"]) {
case "main":
case "Fusebox.defaultFuseaction":
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;
}
Keep this file open, and focus back on fbx_Switch.php in the application root. Remember when we created an XFA for the "biography" circuit?
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;
}
Now we're going to adjust the fbx_Switch.php file in /bio to accommodate the XFA we just set up in the application root's fbx_Switch.php. Add the code in bold to the /bio directory's fbx_Switch.php:
switch($Fusebox["fuseaction"]) {
case "main":
case "Fusebox.defaultFuseaction":
include("dsp_main.php");
break;
case "hello_world":
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;
}
Now open dsp_main.php in /bio and save it back down as dsp_hello_world.php. Add the following code to dsp_hello_world.php:
<h3>Biography: Hello World!</h3>
This is the place where the world can come learn about me.
<p>
<?
echo "<a href=\"$PHP_SELF?fuseaction=".$XFA["home"]."\">Home</a>";
?>
Next: Almost There! >>
More PHP Articles
More By Mike Britton