#native_company# #native_desc#
#native_cta#

WebBox (Fusebox) Architecture Page 2

By Bill Holloway
on July 30, 2000

Each webbox is composed of several files and is stored in a single
directory with an index.php3 file. To call a boxaction, the desired
webbox’s index.php3 URL is called and also passed the name of the boxaction to
call along with any arguments to it. A typical URL style call would
look like:


<a href="/people/index.php3?boxaction=viewcustomer&custid=12345">View Customer</a>

A typical form-based call to the same boxaction can be written:


<form action="/people/index.php3" method=post>

<index type=hidden name="boxaction" value="viewcustomer">

Enter the customer's ID number:  <input type=text name="custid">

<input type=submit value="View Customer Record">

</form>


A given webbox’s boxactions are implemented in a single class called a
“gateway”. The index.php3 script instantiates the “gateway”
class for its box. A long switch statement on the $boxaction parameter chooses
the boxaction to call. Continuing our “add a customer” example, the relevant
snippet of code from the index.php3 file might look like this:

<?php

$homedir "/www/htdocs/people/";

include $homedir "gateway.php3";

$g = new Gateway_People($homedir);

switch ($boxaction) {

    case "viewcustomer":

        
$g->viewCustomer($custid);

        break;

    case "checkauthentication":

        
$g->checkAuthentication($username$password);

        break;

    //

    // Other boxactions

    //

    default:

        
$g->showDefaultPage();

        break;

}

?>

As is clear from this example, the gateway class is stored in a file named
gateway.php3, and the class is named "Gateway_<name>", where <name> is the “name” you’ve given to the box (in our example the name is "People"). The gateway class is stored in a .php3 file to avoid exposing secrets like
passwords or other sensitive information you don’t want the public to see. It
should only contain the class definition, no active script or HTML. Having
the gateway class is necessary for calls to a webbox from script outside its
directory [For you fusebox aficionados out there, the gateway is necessary
because there is no <CFMODULE> tag in PHP which allows you to pass arbitrary
arguments.]