Creating a PHP controller



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, they will appear automatically without changes to the PHP script.Ā  For Grid or Subfile data, an array of values must be sent, and 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.

Examples

The following Rich Display File examples are provided in both RPG and PHP code.