A model is a class that manages the behavior and data of a particular
type of data in Perforce Chronicle. The model provides an API for
retrieving, updating, and removing data. Models can vary greatly: a model's data can be
read-only (e.g. for an external RSS feed) or write-only (for a message
queue) or combinations that involve storage in files, Perforce, databases and other sources.
Place models in the models
folder under your module's folder.
Chronicle provides classes which can be extended when creating a model.
P4Cms_Model
provides a base implementation for data models that have
key/value pairs (fields) along with useful functionality for, optionally, mapping in
accessor/mutator methods for the underlying fields. P4Cms_Model
does
not provide any storage or retrieval allowing you to use an arbitrary backend.
The P4Cms_Record
class adds persistent storage of data models in
Perforce and is recommended if that is your intended datastore. Lastly
P4Cms_Record_PubSubRecord
broadcasts events such as
preSave, postSave, query,
allowing other modules to participate in your model's life-cycle. This subject is covered in
greater detail in our API
documentation.
Here is the skeleton of a model based on P4Cms_Model
for the
Foo
module:
<?php /** * Model description * * @copyright copyright info * @license license info * @version version info */ class Foo_Model_Bar extends P4Cms_Model { // define the fields this model requires protected static $_fields = array( 'type', 'label', ); /** * Description * * @return string The identifier in the form <type>-<label> */ public function getId() { return $this->getValue('type') . '-' . $this->getValue('label'); } }