ExpressionEngine Docs

Channel Field Group Model

class ExpressionEngine\Model\Channel\ChannelFieldGroup

Properties

Required

Optional

Relationships

Methods

Events

This model has no events.

Examples

Get a Channel Field

ee('Model')->get('ChannelFieldGroup', 2)->first();

Change a Field Group Name

$group = ee('Model')->get('ChannelFieldGroup', 2)->first();

$group->group_name = 'A New Group Name';

// Validate and Save.
$result = $group->validate();

if ($result->isValid())
{
  $group->save();
}

Create a Field Group

$group = ee('Model')->make('ChannelFieldGroup');

// Set Required Fields
$group->site_id     = ee()->config->item('site_id');
$group->group_name  = 'A New Group';

// Validate and Save.
$result = $field->validate();

if ($result->isValid())
{
  $field->save();
}

Add Fields to Group

$group = ee('Model')->get('ChannelFieldGroup', 2)->first();

// Get the Field Objects.  Note the plural differences.
$group->ChannelFields = ee('Model')->get('ChannelField', array(4,5,6))->all();

// Validate and Save.
$result = $field->validate();

if ($result->isValid())
{
  $field->save();
}

Assign a group to a Channel

// Get the Field Group object.
$group = ee('Model')->get('ChannelFieldGroup', 2)->first();

// Get the Channel object for each channel and assign using the Relationship.
$group->Channels = ee('Model')->get('Channel', array(2))->all();

// Validate and Save.
$result = $field->validate();

if ($result->isValid())
{
  $field->save();
}