public $_extended_field
Override this in your child class to tell the ExtendedModel which field contains your extended properties.
public __construct ($vals = false, $is_new = true, $lock_level = 0)
Need to separate verify list for regular and extended attributes, so we override the constructor to do so.
public put ()
Need to verify extended fields, so we override the put()
method.
Note: On update forms, call update_extended()
if the fields were
set by the admin/util/extended
handler.
public update_extended ()
Look for _extended
field and auto-populate extended attributes.
Will unset $_POST['_extended']
as a side-effect. Call this before
calling put()
on update forms that use the admin/util/extended
handler.
public __get ($key)
Dynamic getter for user properties. If you get the field specified
in the child class's $_extended_field
property, it will automatically
unserialize it into an array for you.
If an extended property has been defined in the $verify
list, you can
also get it directly using the usual $model->property
syntax.
public __set ($key, $val)
Dynamic setter for extended properties field. If you set the field
specified in the child class's $_extended_field
property, it will
automatically serialize it into JSON for storage.
If an extended property has been defined in the $verify
list, you can
also set it directly using the usual $model->property = '...'
syntax.
ExtendedModel extends Model to include the ability to add arbitrary values to a single field that will be JSON encoded in storage and transparently decoded in use. This allows you to extend your Model data with any number of additional values without needing to change your schema.
Note that these values are not indexable directly, but for additional data that you don't need to search on, this can be useful. You can also build simple additional tables for indexing associated data that does need to be searched on, but that is outside of the scope of this class.
Usage:
1. By specifying allowed extended fields in
$verify
2. By accessing the extradata field directly (will automatically serialize and unserialize for you), or through the
ext()
method: