Skip to content
Photis Patriotis edited this page Dec 13, 2013 · 3 revisions

The basis for communication of a MABI API is the data model. The data model maps out the different models that your API uses and the relations between them. The different models are defined in an API by deriving the core \MABI\Model class.

How to Define a Model

Here is an example of a Model definition:

class Recipe extends \MABI\Model {
  /**
   * Unique identifier for the recipe.
   *
   * @var string
   * @field id
   */
  public $recipeId;

 /**
   * The average rating for this recipe across all users
   *
   * @var float
   */
  public $averageRating;

  /**
   * @var Food[]
   */
  public $foods;

  /**
   * The rating that the app needs to receive. Only 
   * filled for the current user
   *
   * @field external
   * @var int
   */
  public $myRating;

  /**
   * All of the ratings for this recipe for all users
   *
   * @field internal
   * @var array
   */
  public $ratings;
}

Extension

\MABI\Model is the common base for all models in the framework. Models themselves are also easily extendible. If you had an Order model, you may extend it to create a ShippedOrder model, which may add fields and functionality.

Fields

The class properties or fields should be strongly typed with the standard @var annotations. These annotations will let other languages, on the receiving end, know the types and relations within models.

Sub-Models

How to use a model

Initialization

Core queries

Custom Queries

Common Patterns

Controller Connection

RESTModelController

ModelController

Documentation