zajField
zajField vs zajDb
These two classes may seem similar at first (both are model field definition classes) but they serve different purposes. The zajDb
class simply defines the options and parameters of a data type. On the other hand, zajField
is aware of the model context as well and is responsible for (among other things) database creation and update, validation, and preprocessing before the data is saved or returned.
Also, while zajDb
is simply a shell class with some properties, zajField
is the class which is extended when defining data types. See /system/plugins/_jquery/fields/*.field.php
for implementations of the default data types available in Outlast Framework.
Properties
- string
$name
The name of the field within the model - string
$type
The name of the Outlast Framework data type. Each data type must be defined as a zajField class. - array
$options
An associated array of options. Options can be set as arguments
Static methods
- zajField
create(string $name, zajDb $field_def, string $class_name='')
A static create method used to initialize this object. You can also usezajDb->get_field($class_name)
(see docs) to createzajField
objects.
Instance methods
- boolean
validation(mixed $input)
Check to see if input data is valid. Returns true if validation was successful, false otherwise. - mixed
get(mixed $data, zajModel &$object)
Preprocess the data before returning the data from the database. The first param is the data, the second is a pointer to the actual object whose field is being retrieved. - array
save(mixed $data, zajModel &$object)
Preprocess the data before saving to the database. The first param is the data, the second is a pointer to the actual object whose field is being saved. Returns an array where the first parameter is the database update, the second is the object update. - bool|string
filter(zajFetcher &$fetcher, array $filter)
This is called when a filter() or exclude() methods are run on this field. It is actually executed only when the query is being built. The first parameter is a pointer to the “parent” fetcher which is being filtered. The second is an array of values specifying what type of filter this is. Returns false by default. Otherwise it can return the generated filter SQL query. See examples formanytoone
and other connection field types. - array
table()
This method allows you to create a subtable which is associated with this field. Seemanytomany
field definition for an example. - array
database()
Defines the structure and type of this field in the mysql database. See here for more documentation on this. - mixed
duplicate(mixed $data, zajModel &$object)
Duplicates the data when duplicate() is called on a model object. This method can be overridden to add extra processing before duplication. See built-in ordernum as an override example.
Magic methods
- boolean
__onInputGeneration(array $param_array, zajCompileSource &$source)
This method is called just before the input field is generated. Here you can set specific variables and such that are needed by the field’s GUI control. The first parameter is an array of parameters passed by the input field tag. This is the same as for tag definitions. The second parameter is a pointer to the source file object which contains this tag. See here for more docs on this.