PHP code example of kingsquare / communibase-connector-php

1. Go to this page and download the library: Download kingsquare/communibase-connector-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kingsquare / communibase-connector-php example snippets



use Communibase\Connector;

$cb = new Connector('<your api key here>');
$peopleNamedTim = $cb->search('Person', ['firstName' => 'Tim'], ['limit' => 5]);
print_r($peopleNamedTim);


$cbc->search($entityType, $selector, $params): entity[];

$cbc->getAll($entityType, $params): entity[];

$cbc->getById($entityType, $id, $params, $version): entity;

$cbc->getByIds($entityType, $ids, $params): entity[];

$cbc->getId($entityType, $selector): string;

$cbc->getIds($entityType, $selector, $params): null|string[];

$cbc->getByRef($ref[, $parent]): entity

$cbc->getTemplate($entityType): array;

$cbc->getHistory($entityType, $id): array;

$cbc->update($entityType, $properties): responseData;

$cbc->destroy($entityType, $id): responseData;

$cbc->generateId(): string - Generate a new, fresh Communibase ID

//Use for Files only to get a string with the binary contents
$cbc->getBinary(id): string;


[
  'firstName' => 'Tim',
  'addresses' => [
    [
      'street' => 'Breestraat',
      // ...
    ], 
    // ...
  ]
]

try {
  $person = $cbc->getById('Person', '_PERSON_ID_');
} catch (\Communibase\Exception $e) {
  echo $e->getMessage();
}

try {
  $person = $cbc->update('Person', [...]);
} catch (\Communibase\Exception $e) {
  //get an array of errors, per property:
  //  [
  //    [
  //      'field' => '<string>',
  //      'message' => '<string>'
  //    ]
  //  ]
  print_r($e->getErrors());
}

composer