Overview

Namespaces

  • Charcoal
    • Loader
    • Model
      • Service
      • ServiceProvider
    • Source
      • Database
    • Validator

Classes

  • AbstractMetadata
  • AbstractModel
  • Collection
  • Model
  • ModelMetadata
  • ModelValidator

Interfaces

  • CollectionInterface
  • DescribableInterface
  • MetadataInterface
  • ModelInterface

Traits

  • DescribableTrait
  • Overview
  • Namespace
  • Class

Class Model

Charcoal Model class

The Charcoal Model

The Charcoal Model UML
The Charcoal Model Class Diagram

Custom Object Type

It is possible to attach a custom object type ($_obj_type) to a Model. This will allow the various loaders (metadata and source data)

Metadata

In Charcoal, all models are held in an instance of \Charcoal\Model\Model and its configuration meta-data structure is defined in a \Charcoal\Model\Metadata object.

Loading metadata

To access the metadata, use $this->metadata(). To set metadata, use either

Properties

The Model Attributes are stored in \Charcoal\Property\PropertyInterface objects. The properties are defined in the Model's metadata and can be accessed either with p($ident) to retrieve a property or with properties() to get all properties.

Data Source

The Model data (which is stored internally in the class) can be stored in a storage Source object. There is only one source type currently implemented: \Charcoal\Source\Database.

Loading from source

...

Loading into Collection

...

Data validation

Once an object has had its data filled (from a form, database, or other source), it is possible to check wether the data is conform to the object definition, as defined by it's properties and meta-properties. This check is done with the validate() function.

The validate() method always return a boolean (true for success and false if there was any validation error(s)). The validation details are held in a Validator object which can then be accessed with the validator() method.

Rendering a model

Every Charcoal Model can be rendered with the help of a View and a ViewController. Or, more precisely, a \Charcoal\View\ModelView and a \Charcoal\View\ModelViewController.

Charcoal\Config\AbstractEntity
Extended by Charcoal\Model\AbstractModel implements Charcoal\Model\ModelInterface, Charcoal\Model\DescribableInterface, Charcoal\Property\DescribablePropertyInterface, Psr\Log\LoggerAwareInterface, Charcoal\Source\StorableInterface, Charcoal\Validator\ValidatableInterface, Charcoal\View\ViewableInterface uses Psr\Log\LoggerAwareTrait (not available) Charcoal\Model\DescribableTrait, Charcoal\Property\DescribablePropertyTrait (not available) Charcoal\Source\StorableTrait, Charcoal\Validator\ValidatableTrait, Charcoal\View\ViewableTrait (not available)
Extended by Charcoal\Model\Model
Namespace: Charcoal\Model
Located at Charcoal/Model/Model.php
Methods inherited from Charcoal\Model\AbstractModel
__construct(), createMetadata(), createSource(), createValidator(), createView(), data(), defaultData(), flatData(), loadFromL10n(), mergeData(), objType(), preSave(), preUpdate(), propertyValue(), save(), saveProperties(), setData(), setDependencies(), setFlatData(), setIdFromData()
Methods inherited from Charcoal\Validator\ValidatableInterface
setValidator(), validate(), validator()
Methods inherited from Charcoal\Source\StorableInterface
delete(), id(), key(), load(), loadFrom(), loadFromQuery(), setId(), setKey(), source(), update()
Methods inherited from Charcoal\Model\DescribableInterface
loadMetadata(), metadata(), metadataIdent(), setMetadata(), setMetadataIdent(), setMetadataLoader()
Methods inherited from Charcoal\Model\ModelInterface
p(), properties(), property()
Methods used from Charcoal\Model\DescribableTrait
generateMetadataIdent(), loadMetadata(), metadata(), metadataIdent(), metadataLoader(), setMetadata(), setMetadataIdent(), setMetadataLoader()
Methods used from Charcoal\Source\StorableTrait
delete(), id(), key(), load(), loadFrom(), loadFromQuery(), postDelete(), postSave(), postUpdate(), preDelete(), setId(), setKey(), setSource(), setSourceFactory(), source(), sourceFactory(), update()
Methods used from Charcoal\Validator\ValidatableTrait
setValidator(), validate(), validator()
Constants inherited from Charcoal\Model\AbstractModel
DEFAULT_SOURCE_TYPE
Properties used from Charcoal\Model\DescribableTrait
$metadata, $metadataIdent, $metadataLoader
Properties used from Charcoal\Source\StorableTrait
$id, $key, $sourceFactory
Properties used from Charcoal\Validator\ValidatableTrait
$validator
API documentation generated by ApiGen