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

From Alpine Linux
Line 76: Line 76:
# runs any existing ''worker.mvc.post_exec'' function
# runs any existing ''worker.mvc.post_exec'' function
# gets the view function and parameters from ''view_resolver''
# gets the view function and parameters from ''view_resolver''
# executes the view with the result of the ''worker.action''
# executes the view with the result of the ''worker.'''action'''''
# calls ''destroy'' to destroy the mvc object
# calls ''destroy'' to destroy the mvc object
# and returns the result of the ''worker.action''
# and returns the result of the ''worker.'''action'''''


If an error occurs, an exception_handler function is run.  If possible, the exception handler of the new mvc object is run, otherwise ''self::exception_handler'' function handles the error.  If an exception occurs after creating the new mvc object, ''mvc.on_unload'' is guaranteed to run, but ''mvc.post_exec'' is not.
If an error occurs, an exception_handler function is run.  If possible, the exception handler of the new mvc object is run, otherwise ''self::exception_handler'' function handles the error.  If an exception occurs after creating the new mvc object, ''mvc.on_unload'' is guaranteed to run, but ''mvc.post_exec'' is not.

Revision as of 15:05, 15 May 2008

acf_www-controller.lua reference

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

build_menus ( self )

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

check_permission ( self, controller, action )

(internal function) 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.

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

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

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

dispatch_component ( str, clientdata, suppress_view )

(internal function) This function is made available to each view file to allow loading of components (sub-actions). It will launch a new controller/action, passing any clientdata, and return the result of the action. If suppress_view is not true, it will display the component action's view.

create_helper_library ( self )

(internal function) Creates a helper library to be passed to each view. Currently, the only function passed is dispatch_component, but in the future functions that need access to self may be added.

view_resolver ( self )

(internal function) Returns a function that will run the template and view. The template is found with find_template, and the view with find_view. Also generates and returns the view parameters besides viewtable.

mvc.on_load ( self, parent )

Sets up self.conf and 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.

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 found while displaying a component, an error message is output instead.

If the message.type is "redir_to_referrer", then issues a 302 Moved to the client, with the target of the redirect being the referring page.

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

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

dispatch ( self, prefix, controller, action )

Overload of the MVC dispatch function to check permissions (and redirect if not allowed), handle components, and pass more data to the view. Controller actions are executed in a protected xpcall.

  1. Checks if user has permission to access this controller/action by calling check_permission
    1. If no permission to action, redirects to default action
    2. If no permission to controller, redirects to default controller/action
  2. Creates a self:new ( prefix .. controller) mvc object
  3. runs any existing worker.mvc.pre_exec function
  4. runs the worker.action
  5. runs any existing worker.mvc.post_exec function
  6. gets the view function and parameters from view_resolver
  7. executes the view with the result of the worker.action
  8. calls destroy to destroy the mvc object
  9. and returns the result of the worker.action

If an error occurs, an exception_handler function is run. If possible, the exception handler of the new mvc object is run, otherwise self::exception_handler function handles the error. If an exception occurs after creating the new mvc object, mvc.on_unload is guaranteed to run, but mvc.post_exec is not.

redirect ( self, str )

Cause a redirect to the specified path. If a prefix or controller is not found in the string, use the current prefix and/or controller. If an action is not found in the string, use the default action. The actual redirection is defined in exception_handler. This function can be called by an action to redirect to another action rather than display it's own view. Note: The controller post_exec function will not be called after redirect is called.

redirect_to_referrer ( self )

Cause a redirect to the referring page. The actual redirection is defined in exception_handler. This function can be called by an action to redirect to the referring page rather than display it's own view. This is useful in actions that are used as components. Note: The controller post_exec function will not be called after redirect_to_referrer is called.

cfe ( table )

Returns a table with value, type, and label 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, or label.

logevent ( message )

Writes a message to the acf log file.