Abstract class Phalcon\Mvc\Model\MetaData

implements Phalcon\Di\InjectionAwareInterface, Phalcon\Mvc\Model\MetaDataInterface

Source on GitHub

Because Phalcon\Mvc\Model requires meta-data like field names, data types, primary keys, etc. this component collect them and store for further querying by Phalcon\Mvc\Model. Phalcon\Mvc\Model\MetaData can also use adapters to store temporarily or permanently the meta-data.

A standard Phalcon\Mvc\Model\MetaData can be used to query model attributes:

  1. <?php
  2. $metaData = new \Phalcon\Mvc\Model\MetaData\Memory();
  3. $attributes = $metaData->getAttributes(
  4. new Robots()
  5. );
  6. print_r($attributes);

Constants

integer MODELS_ATTRIBUTES

integer MODELS_PRIMARY_KEY

integer MODELS_NON_PRIMARY_KEY

integer MODELS_NOT_NULL

integer MODELS_DATA_TYPES

integer MODELS_DATA_TYPES_NUMERIC

integer MODELS_DATE_AT

integer MODELS_DATE_IN

integer MODELS_IDENTITY_COLUMN

integer MODELS_DATA_TYPES_BIND

integer MODELS_AUTOMATIC_DEFAULT_INSERT

integer MODELS_AUTOMATIC_DEFAULT_UPDATE

integer MODELS_DEFAULT_VALUES

integer MODELS_EMPTY_STRING_VALUES

integer MODELS_COLUMN_MAP

integer MODELS_REVERSE_COLUMN_MAP

Methods

final protected _initialize (Phalcon\Mvc\ModelInterface $model, mixed $key, mixed $table, mixed $schema)

Initialize the metadata for certain table

public setDI (Phalcon\DiInterface $dependencyInjector)

Sets the DependencyInjector container

public getDI ()

Returns the DependencyInjector container

public setStrategy (Phalcon\Mvc\Model\MetaData\StrategyInterface $strategy)

Set the meta-data extraction strategy

public getStrategy ()

Return the strategy to obtain the meta-data

final public readMetaData (Phalcon\Mvc\ModelInterface $model)

Reads the complete meta-data for certain model

  1. <?php
  2. print_r(
  3. $metaData->readMetaData(
  4. new Robots()
  5. )
  6. );

final public readMetaDataIndex (Phalcon\Mvc\ModelInterface $model, mixed $index)

Reads meta-data for certain model

  1. <?php
  2. print_r(
  3. $metaData->readMetaDataIndex(
  4. new Robots(),
  5. 0
  6. )
  7. );

final public writeMetaDataIndex (Phalcon\Mvc\ModelInterface $model, mixed $index, mixed $data)

Writes meta-data for certain model using a MODEL_* constant

  1. <?php
  2. print_r(
  3. $metaData->writeColumnMapIndex(
  4. new Robots(),
  5. MetaData::MODELS_REVERSE_COLUMN_MAP,
  6. [
  7. "leName" => "name",
  8. ]
  9. )
  10. );

final public readColumnMap (Phalcon\Mvc\ModelInterface $model)

Reads the ordered/reversed column map for certain model

  1. <?php
  2. print_r(
  3. $metaData->readColumnMap(
  4. new Robots()
  5. )
  6. );

final public readColumnMapIndex (Phalcon\Mvc\ModelInterface $model, mixed $index)

Reads column-map information for certain model using a MODEL_* constant

  1. <?php
  2. print_r(
  3. $metaData->readColumnMapIndex(
  4. new Robots(),
  5. MetaData::MODELS_REVERSE_COLUMN_MAP
  6. )
  7. );

public getAttributes (Phalcon\Mvc\ModelInterface $model)

Returns table attributes names (fields)

  1. <?php
  2. print_r(
  3. $metaData->getAttributes(
  4. new Robots()
  5. )
  6. );

public getPrimaryKeyAttributes (Phalcon\Mvc\ModelInterface $model)

Returns an array of fields which are part of the primary key

  1. <?php
  2. print_r(
  3. $metaData->getPrimaryKeyAttributes(
  4. new Robots()
  5. )
  6. );

public getNonPrimaryKeyAttributes (Phalcon\Mvc\ModelInterface $model)

Returns an array of fields which are not part of the primary key

  1. <?php
  2. print_r(
  3. $metaData->getNonPrimaryKeyAttributes(
  4. new Robots()
  5. )
  6. );

public getNotNullAttributes (Phalcon\Mvc\ModelInterface $model)

Returns an array of not null attributes

  1. <?php
  2. print_r(
  3. $metaData->getNotNullAttributes(
  4. new Robots()
  5. )
  6. );

public getDataTypes (Phalcon\Mvc\ModelInterface $model)

Returns attributes and their data types

  1. <?php
  2. print_r(
  3. $metaData->getDataTypes(
  4. new Robots()
  5. )
  6. );

public getDataTypesNumeric (Phalcon\Mvc\ModelInterface $model)

Returns attributes which types are numerical

  1. <?php
  2. print_r(
  3. $metaData->getDataTypesNumeric(
  4. new Robots()
  5. )
  6. );

public string getIdentityField (Phalcon\Mvc\ModelInterface $model)

Returns the name of identity field (if one is present)

  1. <?php
  2. print_r(
  3. $metaData->getIdentityField(
  4. new Robots()
  5. )
  6. );

public getBindTypes (Phalcon\Mvc\ModelInterface $model)

Returns attributes and their bind data types

  1. <?php
  2. print_r(
  3. $metaData->getBindTypes(
  4. new Robots()
  5. )
  6. );

public getAutomaticCreateAttributes (Phalcon\Mvc\ModelInterface $model)

Returns attributes that must be ignored from the INSERT SQL generation

  1. <?php
  2. print_r(
  3. $metaData->getAutomaticCreateAttributes(
  4. new Robots()
  5. )
  6. );

public getAutomaticUpdateAttributes (Phalcon\Mvc\ModelInterface $model)

Returns attributes that must be ignored from the UPDATE SQL generation

  1. <?php
  2. print_r(
  3. $metaData->getAutomaticUpdateAttributes(
  4. new Robots()
  5. )
  6. );

public setAutomaticCreateAttributes (Phalcon\Mvc\ModelInterface $model, array $attributes)

Set the attributes that must be ignored from the INSERT SQL generation

  1. <?php
  2. $metaData->setAutomaticCreateAttributes(
  3. new Robots(),
  4. [
  5. "created_at" => true,
  6. ]
  7. );

public setAutomaticUpdateAttributes (Phalcon\Mvc\ModelInterface $model, array $attributes)

Set the attributes that must be ignored from the UPDATE SQL generation

  1. <?php
  2. $metaData->setAutomaticUpdateAttributes(
  3. new Robots(),
  4. [
  5. "modified_at" => true,
  6. ]
  7. );

public setEmptyStringAttributes (Phalcon\Mvc\ModelInterface $model, array $attributes)

Set the attributes that allow empty string values

  1. <?php
  2. $metaData->setEmptyStringAttributes(
  3. new Robots(),
  4. [
  5. "name" => true,
  6. ]
  7. );

public getEmptyStringAttributes (Phalcon\Mvc\ModelInterface $model)

Returns attributes allow empty strings

  1. <?php
  2. print_r(
  3. $metaData->getEmptyStringAttributes(
  4. new Robots()
  5. )
  6. );

public getDefaultValues (Phalcon\Mvc\ModelInterface $model)

Returns attributes (which have default values) and their default values

  1. <?php
  2. print_r(
  3. $metaData->getDefaultValues(
  4. new Robots()
  5. )
  6. );

public getColumnMap (Phalcon\Mvc\ModelInterface $model)

Returns the column map if any

  1. <?php
  2. print_r(
  3. $metaData->getColumnMap(
  4. new Robots()
  5. )
  6. );

public getReverseColumnMap (Phalcon\Mvc\ModelInterface $model)

Returns the reverse column map if any

  1. <?php
  2. print_r(
  3. $metaData->getReverseColumnMap(
  4. new Robots()
  5. )
  6. );

public hasAttribute (Phalcon\Mvc\ModelInterface $model, mixed $attribute)

Check if a model has certain attribute

  1. <?php
  2. var_dump(
  3. $metaData->hasAttribute(
  4. new Robots(),
  5. "name"
  6. )
  7. );

public isEmpty ()

Checks if the internal meta-data container is empty

  1. <?php
  2. var_dump(
  3. $metaData->isEmpty()
  4. );

public reset ()

Resets internal meta-data in order to regenerate it

  1. <?php
  2. $metaData->reset();

abstract public read (mixed $key) inherited from Phalcon\Mvc\Model\MetaDataInterface

abstract public write (mixed $key, mixed $data) inherited from Phalcon\Mvc\Model\MetaDataInterface