document

Creates a new Document object, using its constructor.


document([id], [content])

Arguments Type Description
id string Optional document unique ID
content JSON object Optional document content

Return Value

Returns the newly created Document object.

Usage

Copied to clipboard!

<?php

use \Kuzzle\Kuzzle;
use \Kuzzle\Document;

$documentId = 'foobar';
$documentContent = [
  'title' => 'foo',
  'content' => 'bar'
];

$kuzzle = new Kuzzle('localhost');
$dataCollection = $kuzzle->collection('collection', 'index');
$document = $dataCollection->document($documentId, $documentContent);

// $document instanceof Document

try {
  $document->save();
}
catch (ErrorException $e) {

}