lang |
---|
php |
class ExpressionEngine\Model\Channel\ChannelEntry
[TOC]
The Channel the entry belongs to.
The user that published the entry.
The current status of the entry.
Selected categories the entry has.
If enabled, the entry autosaves.
Entries that are related to this entry.
Entries that are related to this entry.
If enabled, previous versions of the entry.
Comments for the entry.
Comment subscriptions for the entry.
The site the entry is apart of.
$entry_id = 50;
$entry_object = ee('Model')
->get('ChannelEntry')
->filter('entry_id', $entry_id)
->first();
Alternatively using the Entry ID as the Primary Key:
$entry_id = 50;
$entry_object = ee('Model')
->get('ChannelEntry', $entry_id)
->first();
$entry = ee('Model')->make('ChannelEntry');
$entry->author_id = ee()->session->userdata('member_id'); // Returns currently Logged-in user ID.
$entry->channel_id = 1;
$entry->title = 'An Awesome Title';
$entry->url_title = ee('Format')->make('Text', 'An Awesome Title')->urlSlug()->compile(); // Returns an-awesome-title. Must be unique.
$entry->status = ee('Model')->get('Status', 1)->first()->status; // Returns 'open';
$entry->entry_date = ee()->localize->now; // Returns time in seconds: 1623945317
// Validate and Save.
$result = $entry->validate();
if ($result->isValid()) {
$entry->save();
}
$entry->entry_id; // Will now return the new Entry ID.
$entry_id = 3;
// Get the entry object.
$entry = ee('Model')->get('ChannelEntry', $entry_id)->first();
// Returns 'closed'.
$entry->status = ee('Model')->get('Status', 2)->first()->status;
// Validate and Save.
$result = $entry->validate();
if ($result->isValid())
{
$entry->save();
}
// The parent entry.
$entry_id = 1;
// Get the Entry's object.
$entry = ee('Model')->get('ChannelEntry', $entry_id)->first();
// Get the children relationship. Returns entry objects.
$children = $entry->Children;
// Will output array(2, 3, 4...etc);
$children_ids = $children->pluck('entry_id');
As One Line:
$children_ids = ee('Model')->get('ChannelEntry', 1)->first()->Children->pluck('entry_id');
Note that relationships can not be set this way.
// Get a Channel Entry object.
$entry = ee('Model')->get('ChannelEntry', 5)->first();
// Get the field data.
$field_data = $entry->field_id_5;
// Using Variables.
$field_id = 5;
$field_data = $entry->{'field_id_'.$field_id};
// Get a Channel Entry object.
$entry = ee('Model')->get('ChannelEntry', 5)->first();
// Set the field data.
$entry->field_id_5 = 'New Data';
// Validate and Save.
$result = $entry->validate();
if ($result->isValid())
{
$entry->save();
}