ACF acf www-controller.lua reference: Difference between revisions

From Alpine Linux
Line 14: Line 14:


Sets up sane defaults in ''self.conf'' and fills in ''self.sessiondata''.  If the client reports a session id, this function will attempt to load the existing session.  If not, a new session is created and ''build_menus'' is called to fill in the permissions and menu tables.
Sets up sane defaults in ''self.conf'' and fills in ''self.sessiondata''.  If the client reports a session id, this function will attempt to load the existing session.  If not, a new session is created and ''build_menus'' is called to fill in the permissions and menu tables.
=== mvc.on_unload ( self ) ===
Saves the session data before returning.  This function will be called after the action is complete and before the view is displayed.


=== mvc.check_permission ( self, controller, action ) ===
=== mvc.check_permission ( self, controller, action ) ===


Returns a boolean to tell whether or not this user is permitted to access this controller/action combo.  The decision is based upon the permissions table in ''self.sessiondata''.
Returns a boolean to tell whether or not this user is permitted to access this controller/action combo.  The decision is based upon the permissions table in ''self.sessiondata''.
=== mvc.post_exec ( self ) ===
Saves the session data before returning.  This function will be called after the action is complete and before the view is displayed.  The exception handler also makes sure to call this function.


=== find_template (appdir, prefix, controller, action, viewtype ) ===
=== find_template (appdir, prefix, controller, action, viewtype ) ===
Line 43: Line 43:


=== exception_handler ( self, message ) ===
=== exception_handler ( self, message ) ===
The function first calls ''mvc.post_exec'' to make sure the session data is saved.  It then handles the exception as follows:


If ''message'' is a table and message.type="redir", then issues a 302 Moved to the client, with the target of the redirect being ''message.prefix/message.controller/message.action message.extra''
If ''message'' is a table and message.type="redir", then issues a 302 Moved to the client, with the target of the redirect being ''message.prefix/message.controller/message.action message.extra''

Revision as of 14:57, 24 April 2008

acf_www-controller.lua reference

The acf_www-controller.lua provides the basic view resolver, exception handler, and application-wide functions for the acf web application.

build_menus ( self )

Builds the permissions and menu tables and stores them in self.sessiondata for use on each page throughout the user session.

  1. Searches for roles files to determine which controllers and actions the current user has permission to view
  2. Searches for menu files to create the entire menu structure
  3. Removes from the menu any actions for which the user does not have permission

mvc.on_load ( self, parent )

Sets up sane defaults in self.conf and fills in self.sessiondata. If the client reports a session id, this function will attempt to load the existing session. If not, a new session is created and build_menus is called to fill in the permissions and menu tables.

mvc.on_unload ( self )

Saves the session data before returning. This function will be called after the action is complete and before the view is displayed.

mvc.check_permission ( self, controller, action )

Returns a boolean to tell whether or not this user is permitted to access this controller/action combo. The decision is based upon the permissions table in self.sessiondata.

find_template (appdir, prefix, controller, action, viewtype )

(internal function) Looks for a .lsp (Lua Server Page) template. Looks for the first matching:

  1. appdir/prefix/template-controller-action-viewtype.lsp
  2. appdir/prefix/template-controller-viewtype.lsp
  3. appdir/prefix/template-action-viewtype.lsp
  4. appdir/prefix/template-viewtype.lsp

It repeats through each upper level of prefix until prefix is "nil". Returns the first found lsp, or false.

view_resolver ( self )

Returns a function that will run the template and view. The template is found by find_template, and the view is the first matching:

  1. appdir/prefix/controller-action-viewtype.lsp
  2. appdir/prefix/controller-viewtype.lsp

exception_handler ( self, message )

If message is a table and message.type="redir", then issues a 302 Moved to the client, with the target of the redirect being message.prefix/message.controller/message.action message.extra

If the message.type is "dispatch", then calls the parent (mvc.lua) exception handler.

Otherwise, calls the parent (mvc.lua) exception handler.

This function may be extended in the future (nba 26 Oct 2007)

cfe ( table )

Returns a table with value, type, option, errtxt and name values. If an input table is given in the call, those key/value pairs are added as well.

Guarantees the view will not get a "nil" on value, type, option, errtxt or name.