ExpressionEngine Docs

Member Field Model

class ExpressionEngine\Model\member\memberField

Properties

Required

Optional

Relationships

No Relationships.

Methods

getSettingsValues

Parameter Type Description
Returns array Returns the member field’s settings.

getValues

Parameter Type Description
Returns array Returns an array of field values for the member.

getStructure

Parameter Type Description
Returns object A link back to the Structure object that defines this Content’s structure.

getContentType

Parameter Type Description
Returns string Returns the content type member.

getDataTable

Parameter Type Description
Returns string Returns the name of the table, member_data.

getColumnPrefix

Parameter Type Description
Returns string Returns the prefix for member fields, m_.

Events

Saving with this model will trigger the following events:

Examples

Get All Custom Member Fields

$all_member_fields = ee('Model')
        ->get('MemberField')
        ->fields('m_field_label','m_field_id')
        ->all()
        ->getDictionary('m_field_id', 'm_field_label');

// Example return: [4 => 'My Field Name']

Create a member field

$new_field = ee('Model')->make('MemberField');
$new_field->m_field_type        = 'text';
$new_field->m_field_label       = 'My Member Field';
$new_field->m_field_name        = 'my_member_field';
$new_field->m_field_description = 'A custom member field example';
$new_field->m_field_settings    = array();
$new_field->m_field_show_fmt    = 'n';

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

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

// The field ID is now available.
$field_id = $new_field->m_field_id;

Accessing a custom member field from a member model instance by member field ID

Please note, this is the way to access custom member fields. To access built-in member fields, see below.

$member_id = 3;  // Example member ID
$field_column_name = 'm_field_id_1';  // Based on the field ID being 1

$member = ee('Model')->get('Member', $member_id)->first();
echo $member->$field_column_name;

Accessing a custom member field from a member model instance by member field short name

Please note, this is the way to access custom member fields. To access built-in member fields, see below.

$member_id = 3;  // Example member ID

// Based on the member field short name being `first_name`
$field = ee('Model')->get('MemberField')->filter('m_field_name', 'first_name')->first();
$field_column_name = 'm_field_id_'.$field->m_field_id;

$member = ee('Model')->get('Member', $member_id)->first();
echo $member->$field_column_name;

Accessing built-in member fields from a member model instance

$member_id = 3;  // Example member ID

$member = ee('Model')->get('Member', $member_id)->first();
echo $member->screen_name;