Writing ACF Models: Difference between revisions

From Alpine Linux
(Category:ACF)
(delete Category:HOWTO)
 
Line 18: Line 18:
  local modelresult = versioncontroller.model:get()
  local modelresult = versioncontroller.model:get()


[[Category:ACF]] [[Category:HOWTO]]
[[Category:ACF]]

Latest revision as of 16:05, 21 March 2012

The model provides the core functionality of ACF. The model can read and write files, launch applications, and do anything else necessary to implement the desired functionality. Generally, models provide the ability to modify the system configuration and start/stop services.

Model Basics

The model should implement functions that provide all of the application functionality for its particular purpose. Models should be limited in scope to a particular purpose - i.e. managing a particular service. The controller will call the model functions to implement the user-requested actions.

Input

Model function inputs are specific to the function. Models have access to all of the common Lua libraries. The modelfunctions library is specifically designed to be used by the model and handles some common functionality.

Handling Forms

One of the common functions in a model is to edit certain system variables. In order to work well with the controller (specifically the controllerfunctions.handle_form function), the model should implement a pair of get/set or read/write functions. The get function will create a group of cfe's describing the parameters and containing their current values. The set function will expect to receive the same group of cfe's with new values to be set. Both the get and set functions should validate the values and fill in the cfe errtxt fields. The set function should set all or none of the variables and should fill in the group cfe errtxt field if the set fails. For creating a new object, the same pattern can be followed, with the get function returning empty values.

Advanced

Loading Another Controller

When writing some more advanced or higher-level models, a designer may need to use functionality already implemented in another controller/model. Rather than reimplementing the functionality, the model should load the existing controller and call the controller or model functions directly. Since the model is not using the dispatch function, access to this controller is outside the application's permission checking.

local versioncontroller = self:new("alpine-baselayout/alpineversion")
local versionresult = versioncontroller:read()
-- Here's how you call the model directly
local modelresult = versioncontroller.model:get()