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 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 $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": 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; } 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
blog comments powered by Disqus |
|
|
|
|
|
|
|