Traditionally, PHP scripts output HTML code. However, outputting HTML while also implementing business logic and retrieving data is somewhat cumbersome.
Profound UI alleviates the problem by separating the user interface into a separate Web 2.0 file, called a Rich Display File. Rich Display Files are stored as JSON (JavaScript Object Notation) and constructed outside of the PHP script using the Profound UI Visual Designer. The widgets in the Rich Display File are bound to named fields, which connect the user interface to the PHP script.
Now, instead of outputting HTML code, the PHP controller script only has to fetch the data to display. The data is then automatically merged with the user interface definition in the Rich Display File.
Handling Input
All user input to the controller is received as POST data, even though the Web page itself is never truly posted or submitted. Profound UI utilizes AJAX, instead of submitting and reloading pages, for better performance.
For example, if a Text Box widget is bound to a field named CUSTOMER, $_POST['CUSTOMER'] in your PHP controller can be used to retrieve the customer entered by the user.
Sending Output
Output from the controller is sent as an associative array, encoded in JSON. If the PHP controller returns no output, the default Profound UI End of Session screen is displayed. If you would like, you can avoid this End of Session screen entirely by always returning data from your controller.
The only required array element is ‘view’, which provides a path to the Rich Display File to use for displaying a screen. For example, if you created a simple screen in the Visual Designer, to output this screen, you only need the following line of code in your PHP script.
<? echo json_encode(array('view' => '/dspf/myscreen.json')); ?>
Where /dspf/myscreen.json is the relative URL path to the Rich Display File.
This simple PHP script will display the screen defined by the Visual Designer.
Output Options
The following is a list of options that can be provided with the associative array sent on output:
- view - path to the Rich Display File
- screen / screens – since multiple screens or formats can be defined in the Rich Display File, the ‘screen’ option allows you to specify the name of the screen to display. You can also specify an array of screen names that are to be overlaid using the ‘screens’ options. If ‘screen’ or ‘screens’ is not specified, the first screen within the Rich Display File is displayed
- data – an array of simple name/value pairs used to populate the screen with data. Additional name/value pairs can also be sent. For example, you can send an entire database record to be displayed on the screen, even if some of the database fields are not defined on the display yet. If these fields are later added to the display, the will appear automatically without changes to the PHP script. For Grid or Subfile data, an array of values must be sent -- with each entry in the array should contain an object with name/value pairs corresponding to the cells in the grid.
- controller – redirects control to another PHP controller
- redirect – redirects the browser to another Web site or URL