Bambookit Home    Middleware

Chapter 19. Middleware




Simple middleware operations

Separation of business logic and front end GUI

Using a simple calculator we separate the business logic from the front end GUI. To pass data to the middleware scripts we use the attribute setData, which would collect the labels from the widgets named 'value1' and 'value2' WHEN the action event is called. It must be noted that the 'named' widgets are resolved when needed (when the action event is called)

The uri request will be in the form of URL GET request
add.php?value1=5&value2=7

calculator.xml
<Widget setShape="0,0,200,100">
<Edit setName="value1" setShape="10,10,40,25" setNumeric="true"/>
<Widget setShape="10,50,20,25" setLabel="%2b"/>
<Edit setName="value2" setShape="10,70,40,25" setNumeric="true"/>
<Button setName="equals" setShape="10,120,40,25" addActionTarget="equals,action,loadGui=add.php%2ctrue" setData="value1%2cvalue2"/>
<Widget setName="result" setShape="10,160,40,25"/>
</Widget>


The php extracts the values passed via the GET paramaters in the URL request. The values are added and returned to the widget named 'result'

add.php
<?php extract($_GET); ?>
<Widget setName="result" setLabel=" <?php echo ($value1 + $value2);?>"/>


To add two values in php, you just use the '+' operator. To subtract, '-', to divide, '/', to multiply '*'.
PHP has access to far more mathematical functions from various libraries. For a more complete reference on php, please refer to www.php.net