PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Inserting a document

To insert a document, you need to provide a Zend_Cloud_DocumentService_Document object or associative array of data, as well as the collection in which you are inserting it.

Many providers require that you provide a document ID with your document. If using a Zend_Cloud_DocumentService_Document, you can specify this by passing the identifier to the constructor when you instantiate the object. If using an associative array, the key name will be adapter-specific locations; for example, on Azure, the ID is made up of the PartitionKey and RowKey; on Amazon SimpleDB, the ID is the ItemName; you may also specify the key in the _id field to be more portable.

As such, the easiest and most compatible way to specify the key is to use a Document object.

Example 76. Inserting a document

<?php
// Instantiating and creating the document
$document = new Zend_Cloud_DocumentService_Document(array(
    
'key1' => 'value1',
    
'key2' => 123,
    
'key3' => 'thirdvalue',
), 
"DocumentID");

// inserting into the "mydata" collection
$documents->insertDocument("mydata"$document);

Zend Framework