Writing ACF Views
At its most basic, a view is simply a way to display the result of an action. In practice, a view can be used to display results, handle an HTML form, launch other actions, combine several actions on the same page, provide dynamic interaction, or all of the above.
According to the haserl documentation, the lsp file is parsed to find and execute any Lua code. The Lua code must be enclosed in <% %> or the older <? ?> token markers. While parsing the lsp file and executing the Lua code, the resulting text is output via socket to the web browser.
Since a view is simply a means to display data to the user, it should not directly access any controllers, models, or global variables. The inputs to a view fall into two categories:
There are four parameters passed to each html view page. They are generally accessed as follows:
<? local data, viewlibrary, page_info, session = ... ?>
- form - This is the table returned by the executed action.
- viewlibrary - discussed below
- page_info - A table containing information about the current page, such as the name of the controller and action.
- session - The user session table. This table contains information about the current user, permissions, and command results.
The view has access to all of the common Lua libraries, although some are not designed to be used by the view. There are two libraries specifically designed for use in the view:
- viewlibrary - This library is passed to the view as a parameter. The functions in this library are the only way that a view is allowed to interact with the MVC self variable. Currently the library only contains one function - dispatch_component
- viewfunctions - This library contains common functions used by many views. It should be used for displaying cfe items and forms where possible to maintain compatibility.
To ease development, there are several common views available for use in any controller.
- debug-html.lsp - Used during development to display view parameters.
- filedetails-html.lsp - Displays a form that allows a user to directly edit a file.
- form-html.lsp - Display a basic form with no ordering of fields.
- startstop-html.lsp - Displays Start, Stop, and Restart buttons and the result of a preceding action. Buttons are disabled based upon the process status.
- status-html.lsp - Displays basic status for a process.
- expert-html.lsp - Displays status and startstop components, and uses filedetails-html.lsp to edit a configuration file.
symlinks loading subviews