ACF acf www-controller.lua reference
- 1 acf_www-controller.lua reference
- 1.1 build_menus ( self )
- 1.2 check_permission ( self, controller, action )
- 1.3 find_template ( appdir, prefix, controller, action, viewtype )
- 1.4 find_view ( appdir, prefix, controller, action, viewtype )
- 1.5 dispatch_component ( str, clientdata, suppress_view )
- 1.6 create_helper_library ( self )
- 1.7 view_resolver ( self )
- 1.8 mvc.on_load ( self, parent )
- 1.9 mvc.on_unload ( self )
- 1.10 exception_handler ( self, message )
- 1.11 dispatch ( self, prefix, controller, action )
- 1.12 redirect ( self, str )
- 1.13 redirect_to_referrer ( self )
- 1.14 cfe ( table )
- 1.15 logevent ( message )
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:
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:
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.
- 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
- 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
- gets the view function and parameters from view_resolver
- executes the view with the result of the worker.action
- calls destroy to destroy the mvc object
- 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.