TurboPhp Applications

The TurboPhp application framework is contained in the file TpLib.php. The framework can be used independently of the IDE. A minimal application would look as follows:

// Include the TurboPhp library

include("TpLib.php"); // Instantiate the application object, // specifying the HTML layout file
$app = new TTpApp("layout.html"); // Perform operations and output HTML
echo $app->Run(); // Event code here

Event Functions

Event functions can be attached to objects. Event functions are functions that are called by an object at specific times or situations (called firing the event). For example, a button fires a Click event is when it is clicked; the Click event calls the OnClick event function attached to the object.

The Generate event is fired right before an object is output into HTML. We can use this event to modify or update properties for the object. Here is an example of an OnGenerate event function.

function HelloGenerate(&$inSender)
  $inSender->Content = "Hello World!";

The example event function sets the Content variable of the sender. If we attach this function to an object, then when the TurboPhp application is run, the content of the object will be replaced with Hello World!.

All event functions take a single (reference) parameter, &$inSender, which identifies the object firing the event. All event functions should be declared this way.

Event functions are attached to objects automatically when using the IDE (the values are encoded into the HTML markup), but you can also attach an event function to an object by setting the name of the event function. For example,

$TpLabel1->OnGenerate = 'HelloGenerate';

Object Basics

All TurboPhp objects are extensions of the TTpObj class. The TTpObj class exposes a number of useful fields and methods. Here are some of the useful fields in all TTpObj objects.

 var $App;        // Refers to the TTpApp object that owns this TTpObj
 var $Name;       // Object's name as specified in the tpname markup 
 var $Elt;        // The element from the object markup (e.g. div or input)
 var $Attributes; // Array of HTML attributes
 var $Style;      // String containing the value of the style attribute
 var $Content;    // Text between the start and end tags 
 var $EndTag;     // The end tag for the object (can be empty) 
 var $Hidden;     // True if the object should not be output to HTML 
 var $OnGenerate; // Function to be called when the Generate event is fired

The Attributes associative array initially contains name/value pairs parsed from the HTML markup (special TurboPhp attributes are automatically removed). The values can be accessed or modified like so:

$obj->Attributes['width'] = 48;

The Style string contains the complete value of the style attribute. Instead of modifying this field directly, individual style values should be modified with the Stylize function.

$obj->Stylize('background-color', 'blue');
$obj->Stylize('font-family', '');

In general, fields of a TurboPhp object can be specified in markup using an attribute corresponding to the field prefixed with tp. For example, the attribute tpongenerate, as shown above, specifies a value for the OnGenerate field, and tphidden can be used to set the Hidden field.