webCOMAND

repo::new_object()

Create a new object associated with the repository.

Prototype

Object new_object(mixed $content_type, array $options = [])

Parameters

  • content_type - Content Type of the new object to create, provided as a Content Type OID, Identifier or Object.
  • options - Associative array with zero or more of the following keys.
    • FieldValues - Associative array of key/value pairs where the key is a Content Type Field Identifier and the value is the value to initialize that field to in the new object.  The value can be another object or collection for deep nesting.  These will be set after the Content Type New template is processed.

Return

An Object associated with the current repository.  It's field values will be set to their defaults, including any initialization from it's content type's New template, unless optional FieldValues were passed in.

Example

// create new object based on Content Type Identifier
$contact = $repo->new_object('Contact');

// create new object based on the Content Type object
$type = $repo->get_first("FROM ContentType WHERE Identifier='Contact'");
$contact = $repo->new_object($type);

// create new object based on Content Type OID
$contact = $repo->new_object($type->OID);

// create new object based on Content Type OID and values
$contact = $repo->new_object($type->OID, [
    'FieldValues' => [
        'Name' => 'Jenny',
        'Phone' => '867-5309'
    ]
]);