ACF core principles

While the mvc.lua code provides a generic framework for any lua "mvc"-based application, "acf" is the component that makes the mvc.lua framework into a web configuration Application. Some ideas and rationales for application-wide settings are discussed here.

Use of cfe

A cfe (Configuration Framework Entity) is a way to pass data between a model, controller and view in a common way. There are many ways to do this (e.g. closures, AKClass); use of cfe is an arbitrary decision just to keep development moving forward.

A cfe is a table with some fields guaranteed to exist. It is also a way to abstract user-modifiable data from view-centric HTML input types. ACF isn't necessarily web-only. With a different controller and views, it could be cli (or gui?!). The acf-cli application is an example of this.

Fields in all cfes

cfe's are constructed from a function in mvc.lua that returns an anonymous table with the following fields

FieldDefaultDescription
value""The value of the cfe (e.g. the IP address, hostname, password, etc.)
type"text"The type of entity (see below)
label""User-readable label for the value

The reason for having these fields pre-defined is to allow models, controllers and views to use the indexes without having to first check if they exist. For example the entity will always have a value and type.

cfe's can have other fields. Some common fields that may, or may not, be present:

FieldDescription
errtxtText explaining why validation failed
optionA list of options for this value
descrUser-readable description for the value
seqNumeric sequence suggesting display order for cfe's in a group or form
defaultDefault value (can be displayed to user)
readonlyIf present, indicates that the information is to be displayed, but not editable, typically used in forms

To set fields or overwrite field defaults, specify a table in the argument list to the cfe constructor:

mycfe = cfe({label="User", value="asdf", errtxt="Invalid User"})

is equivalent to

mycfe = {label="User", value="asdf", type="text", errtxt="Invalid User"}

cfe types

The type field of a cfe can be one of the following:

typeDescriptionModifiers
texta text field, typically one line of text
longtexta multi-line text field, like a textarea
selecta select listvalue is the currently selected item
option is an array of select options
multia multi-select listvalue is an array of selected items
option is an array of select options
lista listvalue is an array of strings
booleantrue or false
rawraw binary data
forma set of cfe's that make up a formvalue is a table of cfe's that make up a form (the table should be name-indexed)
option is the command name to save changes (button name for HTML)
descr or errtxt may contain the result of a save attempt
groupa set of cfe's that make up an anonymous groupvalue is a table of grouped cfe's (can be used to pass several items to a view) (the table should be name-indexed)
structurea Lua table with no further type info
passworda password which should not be readable by a user
hiddena hidden field typically containing information used by ACF and not visible to a user

The Model defines the object set

The model is responsible for writing and reading from the running system. The model typically does not need to know which part of a specific acf module it is running under. It is not mandatory that the model be lua "oop" as the rest of the system is. (the model may not have any need to know "self")

Since the model can choose how much or how little of the system to expose, the basic data set should be defined in the model.

This article is issued from Alpinelinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.