Difference between revisions of "ACF acf www-controller.lua reference"

From Alpine Linux
Jump to: navigation, search
(view_resolver ( self ))
(acf_www-controller.lua reference)
Line 3: Line 3:
 
The acf_www-controller.lua provides the basic view resolver, exception handler, and application-wide functions for the acf web application.
 
The acf_www-controller.lua provides the basic view resolver, exception handler, and application-wide functions for the acf web application.
  
=== cfe ( table ) ===
+
=== build_menus ( self ) ===
 +
 
 +
Builds the permissions and menu tables and stores them in ''self.sessiondata'' for use on each page throughout the user session.
 +
 
 +
# Searches for roles files to determine which controllers and actions the current user has permission to view
 +
# Searches for menu files to create the entire menu structure
 +
# 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.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 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.
+
=== mvc.post_exec ( self ) ===
  
Guarantees the view will not get a "nil" on value, type, option, errtxt or name.
+
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 ) ===
  
 
''(internal function)'' Looks for a .lsp (Lua Server Page) template.  Looks for the first matching:
 
''(internal function)'' Looks for a .lsp (Lua Server Page) template.  Looks for the first matching:
Line 15: Line 29:
 
# ''appdir/prefix''/template-''controller-action-viewtype''.lsp
 
# ''appdir/prefix''/template-''controller-action-viewtype''.lsp
 
# ''appdir/prefix''/template-''controller-viewtype''.lsp
 
# ''appdir/prefix''/template-''controller-viewtype''.lsp
# ''appdir/prefix''/template-''controller-action-viewtype''.lsp
 
 
# ''appdir/prefix''/template-''action-viewtype''.lsp
 
# ''appdir/prefix''/template-''action-viewtype''.lsp
 
# ''appdir/prefix''/template-''viewtype''.lsp
 
# ''appdir/prefix''/template-''viewtype''.lsp
Line 21: Line 34:
 
It repeats through each upper level of prefix until prefix is "nil".
 
It repeats through each upper level of prefix until prefix is "nil".
 
Returns the first found lsp, or false.
 
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:
 +
 +
# ''appdir/prefix/controller-action-viewtype''.lsp
 +
# ''appdir/prefix/controller-viewtype''.lsp
  
 
=== exception_handler ( self, message ) ===
 
=== 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''
+
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 the message.type is "dispatch" then calls the parent (mvc.lua) exception handler.
+
If the message.type is "dispatch", then calls the parent (mvc.lua) exception handler.
  
 
Otherwise, calls the parent (mvc.lua) exception handler.
 
Otherwise, calls the parent (mvc.lua) exception handler.
Line 32: Line 54:
 
This function may be extended in the future (nba 26 Oct 2007)
 
This function may be extended in the future (nba 26 Oct 2007)
  
=== view_resolver ( self ) ===
+
=== 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.
  
Returns a function that includes the templates found by find_template
+
Guarantees the view will not get a "nil" on value, type, option, errtxt or name.

Revision as of 15:43, 23 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.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.

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 )

(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 )

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 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.