PHP code example of garchicms / garchi-sdk-php

1. Go to this page and download the library: Download garchicms/garchi-sdk-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/ */

    

garchicms / garchi-sdk-php example snippets


use GarchiCMS\GarchiCMS;

$garchi = new GarchiCMS("YOUR_API_KEY");

$newItem = $garchi->dataItem->create([
    'space_uid' => 'your_space_uid',
    'name' => 'New Item',
    'categories' => [1, 2, 3],
]);

$result = $garchi->dataItem->updateWithStatus([
    'item_id' => 51,
    'space_uid' => 'your_space_uid',
    'name' => 'Winter coat',
]);
// $result['has_draft'] === true: saved as unpublished changes, the published item is unchanged

$result = $garchi->dataItem->updateWithStatus(['item_id' => 51, 'space_uid' => 'your_space_uid', 'make_public' => true]);
// publishes them; on a 409, $result['message'] says why they could not be published

$items = $garchi->dataItem->getAll(['size' => 10]);

$items = $garchi->dataItem->query([
    'uid' => 'your_space_uid',
    'where' => ['all' => [
        ['field' => 'meta.color', 'op' => 'in', 'value' => ['red', 'blue']],
        ['field' => 'price', 'op' => 'lte', 'value' => 50],
    ]],
    'sort' => [['field' => 'price', 'direction' => 'asc']],
    'size' => 20,
]);

// The published items inside a product, in their order
$variants = $garchi->dataItem->getChildren(['uid' => 'your_space_uid', 'item' => 'oak-table']);

// A product with its variants in one call
$product = $garchi->dataItem->get(['item' => 'oak-table', 'children' => ' => ['field' => 'parent_id', 'op' => 'not_exists']]);

$newCategory = $garchi->category->create([
    'category' => 'New Category',
    'space_uid' => 'your_space_uid'
]);

$categories = $garchi->category->getAll();

$review = $garchi->review->create([
    'item_id' => 1,
    'rating' => 5,
    'review_body' => 'Excellent product!',
    'user_email' => '[email protected]',
    'user_name' => 'John Doe'
]);

$reaction = $garchi->reaction->manage([
    'reaction' => 'like',
    'user_identifier' => '[email protected]',
    'review_id' => 1,
    'item_id' => 1,
    'reaction_for' => 'review'
]);

$newSpace = $garchi->space->create([
    'name' => 'New Space',
    'logo' => $yourLogoFile
]);

$pages = $garchi->space->listPages('your_space_uid');

$sectionTemplates = $garchi->space->listSectionTemplates('your_space_uid');

$queryResult = $garchi->compoundQuery->query([
    'dataset' => 'items',
    'fields' => ['name', 'price'],
    'conditions' => ['like', 'gte'],
    'values' => ['%item%', '10'],
    'logic' => ['and']
], ['order_key' => 'name', 'order_by' => 'asc']);

$page = $garchi->headless->getPage([
    'space_uid' => 'your_space_uid',
    'slug' => '/',
    'lang' => 'en-US',
    'mode' => 'live'
]);

try {
    $item = $garchi->dataItem->get(['item' => 1]);
    print_r($item);
} catch (\Exception $error) {
    echo 'Error: ' . $error->getMessage();
}

use GarchiCMS\Contracts\GarchiItem;
use GarchiCMS\Contracts\GarchiCategory;
use GarchiCMS\Contracts\GarchiReview;