The structure of the framework is easy to understand and relies in the “remote scripting” method.
The goal of this technique is to achieve the exchanging of data and instructions between the internet explorer client and the server-side without needing to reload the actual page, just like a desktop application.
Thus, when the application is constructed and sent to the client throw the 'flush' method, the html page sent has a hidden 'iframe' that is the target of all the events that the user fire in the html area.
All events in the html page call to a script called 'p4a_events.php' that returns the JavaScript code necessary to modify the html objects and to synchronize these objects with the PHP objects located at the server-side.
For example:
<td onclick="javascript:target_iframe.location.href='p4a_events.php?event=column_click'">
When the user clicks into the <td> tag, this tag loads into the hidden iframe the result of calling p4a_events.php with the code of the P4A event passed in the query string (GET).
The code loaded in the hidden iframe is all the JavaScript sentences need it to modify the status and even the HTML code of the objects (basically 'div' tags) of the parent document (the html area of the user).
Thus, the bi-directional communication is achieved without the re-loading of entire pages and it makes possible the event oriented programming used in the p4a framework.
*********************************************************************
***************** History of objects and calls. *******************
*********************************************************************
CLIENT-SIDE SERVER-SIDE
The application object
is created:
$myapp = new MyApp(..);
MyApp extends
p4a_Application
The application is
saved into the session
var 'Application'
$_SESSION['Application'] = $myapp;
The flush method is called and
the client html page is contructed
$_SESSION['Application']->flush();
//flush(0)
HTML page <<--------------------
with hidden iframe
|
|
|
Some user event occurs
|
|
The iframe is set as the target
of the result of calling p4a_events.php
with the event code:
iframe.location.ref.=p4a_events.php?event=CODE_EVENT
|
------------------------------------------------------>> p4a_events.php
is executed
Capture the event with its
optional arguments:
foreach( $_GET as $k => $v)
$event[$k] = $v;
Call to the event handler
of the application:
$p4a = & $_SESSION['Application'];
echo $p4a->event_handler( $event);
|
|
|
(My_App.php script)
Business logic, modifying the
status of some objects and calling
to their flush(1) methods:
function event_handler( $_ev, & $_app)
{
switch( $_ev['event'])
{
case "topmenu_op1":
...
$answer .= $_app->
controls_collection['panel01']->
flush(1);
...
return $answer;
Hidden Iframe <<---------------------------
| Returning in the answer the JavaScript
| code that modifies the status of the HTML page
|
|
Hidden iframe receives the code an execute it, modifying
the status of html parent document (the user area)
|