webCOMAND

repo::get_object()

Get a single object from the repository and ensure it is or extends a PHP Class or content type.

Passing in an OID or UUID is more efficient than a cPath and cQL, and than calling get_first() because it doesn't need to be interpreted as a query, and more importantly it will leverage the repository object cache.

Prototype

object get_object(mixed $value, mixed $class = '\\comand\\models\\cObject')

Parameters

  • value - An OID, UUID, cPath, cQL or cObject.  If a cObject is specified, it will only be returned if its content type is or extends the specified class.
  • class - A PHP class that is or extends cObject, a string that represents the fully namespaced path to the same, or a Content Type Identifier.

Return

An object that matches the value or query and is or extends the specified class or content type.  Otherwise NULL.

Example

$contact = $repo->get_object(12345, 'Contact');
if($contact != NULL) {
	echo($contact->Name . " - " . $contact->Phone . "\n");
}