SDK
SDK PHP v3.x
1

You are currently looking at the documentation of a previous version of Kuzzle. We strongly recommend that you use the latest version. You can also use the version selector in the top menu.

document #

Creates a new Document object, using its constructor.


document([id], [content]) #

ArgumentsTypeDescription
idstringOptional document unique ID
contentJSON objectOptional document content

Return Value #

Returns the newly created Document object.

Usage #

<?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) {
}