Comfortable | Docs
  • Comfortable Documentation
  • Concepts
    • Content Repositories
    • Content Types
    • Documents
    • Assets
    • Content Tree
    • Collections
    • Webhooks
    • Team
    • Locales
  • APIs
    • RESTful API
      • Endpoints
      • API Reference
        • Sorting
        • Filters
        • Localisation
        • Fields
        • Includes
        • Search
      • Query Examples
        • Collections
        • Single Documents
        • Single Assets
        • Sorting
        • Filters
        • Includes
    • Image Manipulation
  • SDKs
    • JavaScript
      • Query Options
      • Query All Documents
      • Query a Collection
      • Query a Single Document
      • Query an Alias
      • Query an Asset
      • Example: Filters
      • Example: Sorting
    • Nuxt.js
    • PHP
      • Query All Documents
      • Query Single Document
      • Query Collection
      • Query an Alias
      • Query an Asset
      • Fulltext Search
      • Query by Fields
      • Query by Type
      • Query by Id
      • Query by Tags
  • Guides
    • Vue Blog Example
  • Legal
    • Legal Notice
    • Privacy Policy
Powered by GitBook
On this page
  1. SDKs

PHP

PreviousNuxt.jsNextQuery All Documents

Last updated 6 years ago

The Comfortable PHP SDK can be installed with . Run this command:

composer require comfortable/php-sdk

Usage

Note: This version of the SDK requires PHP 5.6 or greater.

Include the dependency:

<?php
require_once __DIR__ . '/vendor/autoload.php'; // change path as needed

use Comfortable;

Connect to your Repository and make your first request:

$api = Comfortable\Api::connect('<repository-api-id>', '<api-key>');

try {
  // get all documents stored in comfortable (default limit: 25)
  $results = $api->getDocuments()->execute();  
} catch (\RuntimeException $e) {
  echo 'Comfortalbe SDK returned an error: ' . $e->getMessage();
  exit;
}

Full usage Example

<?php

use Comfortable\Api;
use Comfortable\Filter;
use Comfortable\Sorting;
use Comfortable\Includer;

// connect to your repository
$api = Api::connect('<repository-api-id>', '<api-key>');

$results = $api->getDocuments()
  ->limit(10) // limits the result to 10
  ->offset(25) // skip the first 25 documents
  ->locale('en') // receive the document in english
  ->includes(2) // includes 2 levels of relations
  ->includeByFields(
    (new Includer)
      ->add('relatedNews') // include only the relatedNews instead of all relations
  )
  ->embedAssets(true) // embed assets directly inside a document instead of using them as includes
  ->includeTags(["include", "me"]) // include documents with the "include" or "me" tag
  ->excludeTags(["exclude"]) // exclude documents with the "exclude" tag
  ->search('this is a fulltext search') // perform a fulltext search
  ->fields('fields(title)') // name the fields you want to receive by the api
  ->sorting(
    (new Sorting)
      ->add('id', 'ASC', 'meta') // sort the result ascending by id
      ->add('title', 'DESC') // sort the result descending by title
   )
   ->filter(
     (new Filter)
       ->addAnd('date', 'greaterThan', '01-02-2018') // return only documents greaterThan given date
     )
   ->execute();
Composer