Models
Models bind to data objects in the database. A model represents an object carrying data, it has functionality to get/save/delete and can also have logic to transform the data it holds.
The framework supports four data objects in WordPress:
- Posts
- Users
- Taxonomies (categories)
- Options
Post Models
Post models handle data coming from “posts” and “postmeta” tables (in database); are commonly used to hold any type of data (say products, pages, posts, events and any other) and are differentiated using the post type property.
Post models can be created and new types can be registered using Ayuco.
Create command:
Create command is used when the post type related to the model is already defined in WordPress (i.e. pages, posts and attachments).
php ayuco create model:{model}
Where:
- {model}: The name of the model.
Sample:
php ayuco create model:Post
Register command:
Register command is used when a new post type needs to be registered and needs to be related to a model (i.e. books, products, artists and other).
php ayuco register type:{type} {model} {controller}
Where:
- {type}: Post type.
- {model}: Model holding the object.
- {controller}: Controller for automated property saving.
Sample:
php ayuco register type:book Book BookController
User Models
User models are only used to handle data coming from “users” and “usermeta” tables (in database).
User models can be created using Ayuco.
Create command:
php ayuco create usermodel:{model}
Where:
- {model}: The name of the model.
Sample:
php ayuco create usermodel:User
Category Models
Category models handle data coming from “terms” and “termmeta” tables (in database); are commonly used to hold any type of data terminology (say products categories, product types, post categories and any other).
Category models can be created using Ayuco.
Create command:
php ayuco create categorymodel:{model}
Where:
- {model}: The name of the model.
Sample:
php ayuco create categorymodel:ProductCategory
Option Models
Option Models handle data coming from “options” table (in database); are commonly used to hold app configuration settings.
Option models can be created using Ayuco.
Create command:
php ayuco create optionmodel:{model}
Where:
- {model}: The name of the model.
Sample:
php ayuco create optionmodel:App