ACF acf www-controller.lua reference
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.
(internal function) 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
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:
- appdir/prefix/template-controller-action-viewtype.lsp
- appdir/prefix/template-controller-viewtype.lsp
- appdir/prefix/template-action-viewtype.lsp
- 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:
- appdir/prefix/controller-action-viewtype.lsp
- appdir/prefix/controller-viewtype.lsp
has_view ( self )
(internal function) Returns true if there is a .lsp (Lua Server Page) view specifically for this action.
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, pass more data to the view, and allow display of views without actions. Controller actions are executed in a protected xpcall.
- Checks if user has permission to access this controller/action by calling check_permission
- If no permission to action, redirects to default action
- If no permission to controller, redirects to default controller/action
- If the controller/action exists
- Creates a self:new ( prefix .. controller) mvc object
- Runs any existing worker.mvc.pre_exec function
- Runs the worker.action
- Runs any existing worker.mvc.post_exec function
- Calls destroy to destroy the mvc object
- Gets the view function and parameters from view_resolver
- Executes the view with the result of the worker.action
- 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 )
If we've acted on a command, put the result in the session and cause a redirect to the referring page (assuming it's different). If not, check to see if there is a result in the session from a previous redirection. The actual redirection is defined in exception_handler. This function should be called by an action to redirect to the referring page rather than display it's own view. This allows actions that are used as components to display the container view after completing the requested command, and then display the result when reloaded as a component. Note: The controller post_exec function will not be called if redirect_to_referrer causes a redirection.
logevent ( message )
Writes a message to the acf log file.