Models
Models bind to data objects in the database. A model represents an object carrying data, it has the functionality to get/save/delete and can also have logic to transform the data it holds.
The framework supports the following data objects in Wordpress:
- Posts
- Users
- Taxonomies (categories and terms)
- Options
- Comments
- Custom data table (see Database section)
Post Models
Post models handle data coming from "posts" and "postmeta" tables (in the database); they 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}
{model} | The name of the class model to be created. |
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 others).
php ayuco register type:{type} {model} {controller}
{type} | The custom post type to be registered. |
{model} | The name of the class model to be created. |
{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 the database).
User models can be created using Ayuco.
Create command
php ayuco create usermodel:{model}
{model} | The name of the class model to be created. |
Sample:
php ayuco create usermodel:User
Option Models
Option Models handle data coming from "options" table (in the database); they are commonly used to hold app configuration settings.
Option models can be created using Ayuco.
Create command
php ayuco create optionmodel:{model} {id}
{model} | The name of the class model to be created. |
{id} | The id of the model in the database (optional). |
Sample:
php ayuco create optionmodel:MyApp my_app
Term Models
Term models handle data coming from "terms" and "termmeta" tables (in the database); they are commonly used to hold any type of data terminology (say tags, categories and any other).
Term models can be created using Ayuco.
Create command
php ayuco create termmodel:{model} {taxonomy}
{model} | The name of the class model to be created. |
{taxonomy} | (Optional) The taxonomy related to the class. |
Sample:
php ayuco create termmodel:BookPublisher book_publisher
Comment Models
Comment models handle data coming from "comments" and "commentmeta" tables (in the database); they are commonly used to hold any type of data comment or notes attached to a post.
Comment models can be created using Ayuco.
Create command
php ayuco create commentmodel:{model}
{model} | The name of the class model to be created. |
Sample:
php ayuco create commentmodel:BookNote