Table of Contents
Table of Content
Domain-Models in WordPress #
When you use a nnhelpers-Repository to retrieve entries from the database, the data will automatically be mapped to a Model.
Please refer to the Repository docs to find out, how to create the Repository for the Model.
Example Model #
Your Model should always extend the \Nng\Nnhelpers\Domain\Model\CPT\AbstractModel
<?php
namespace My\Extension\Domain\Model\CPT;
use Nng\Nnhelpers\Domain\Model\CPT\AbstractModel;
class Entry extends AbstractModel
{
// auto-mapped from `post.post_title`
public $postTitle;
// auto-mapped from the `postmeta._extname_entry_www`
public $www;
/**
* Example for a computed property
* In your Fluid-template you can access it like any
* other property of the model, e.g. `item.example`
*/
public function getExample() {
return 'works!';
}
}
Inherited propertes from AbstractModel #
The properties inherited from Nng\Nnhelpers\Domain\Model\CPT\AbstractModel
are:
- All fields from the
post
-entry with a lowerCamelCase key. This means thatpost_title
will be accessible as the propertypostTitle
in the Model - The media attached to the WP-Post in the Array
media
and the first media element infirstMedia
. - The categories of the WP-Post in the Array
category
Overview: #
property | type | description |
---|---|---|
ID |
integer |
ID of the WP-Post |
postTitle |
string |
Title (post_title ) of the WP-Post |
postAuthor |
string |
Author (post_author ) of the WP-Post |
... |
... | ... and so on. All fields from post -table |
media |
Array<SysFile> |
All media (images) related to the Post |
firstMedia |
SysFile |
The first media / image of the Post |
categories |
Array<Array> |
List of categories related to Post |
Accessing properties in your Fluid-template #
All properties in the Model can be accessed from Fluid using the dot-syntax. It plays no role, if the properties are static or computed with a getter.
<f:for each="{entries}" as="{entry}">
<h1>{entry.postTitle}</h1>
<f:image src="{entry.firstMedia}" maxWidth="300" />
</f:for>