Skip to content
LEGACY: Directus PHP SDK — PHP Software Development Kit
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.


Type Name Latest commit message Commit time
Failed to load latest commit information.
src only hash password on local connection May 14, 2018
tests test Response toArray method Mar 31, 2018
.editorconfig initial commit Jun 17, 2016
.gitignore ignore .idea Dec 27, 2016
LICENSE Initial commit Mar 8, 2016 notice about legacy version Nov 26, 2018
phpunit.xml phpunit filter coverage to src php files Jun 18, 2016

Directus Logo

Directus 6 PHP SDK (Legacy)

WebsiteDocsAPI ReferenceUser GuideDemoContribute


This codebase is a work-in-progress. The repo is here as a placeholder for anyone interested in contributing to the software development kit. Pull-requests and contributions are welcome!


Build Status Scrutinizer Scrutinizer Coverage

For PHP driven applications, use this SDK to more easily communicate with your Directus managed database.


  • PHP version 5.5 or greater.


Via Composer

You can install the SDK using Composer by adding directus/sdk to your composer.json require list.

  "require": {
    "directus/sdk": "^1.1.1"
  "minimum-stability": "dev",
  "repositories": [{
    "type": "git",
    "url": ""

Make sure dev is the minimum-stability. We are using a forked version of Zend-DB, and because it's not released under any new name or version, we have to set minimum-stability to dev in order to composer find the repository in GitHuba and install Zend-DB.

Then run composer install.

Composer will download all dependencies and copy them into a directory with the name of vendor.

To use the SDK you have to include the composer autoload. The composer autoload is a file that is located in the vendor directory, named autoload.php.

require_once 'vendor/autoload.php';


Database Connection

require 'vendor/autoload.php';

$config = [
    'database' => [
        'hostname' => 'localhost',
        'username' => 'root',
        'password' => '123',
        'database' => 'directus_db',
        // Optional
        // 'port' => 3306,
        // 'charset' => 'utf8'
    'filesystem' => [
        'root' => '/path/to/directus/storage/uploads'

$client = \Directus\SDK\ClientFactory::create($config);
$articles = $client->getItems('articles');

foreach ($articles as $article) {
    echo $article->title . '<br>';

Directus Hosted

You can sign up for a Directus Hosted account at

require 'vendor/autoload.php';

$client = \Directus\SDK\ClientFactory::create('user-token', [
    // the sub-domain in your instance url
    'instance_key' => 'user--instance',
    'version' => '1' // Optional - default 1.1

$articles = $client->getItems('articles');
foreach ($articles as $article) {
    echo $article->title . '<br>';

Your own server

require 'vendor/autoload.php';

$client = \Directus\SDK\ClientFactory::create('user-token', [
    // Directus API Path without its version
    'base_url' => 'http://directus.local',
    'version' => '1' // Optional - default 1.1

$articles = $client->getItems('articles');
foreach ($articles as $article) {
    echo $article->title . '<br>';

Getting the whole response

The whole response is either an Entry or EntryCollection object, it depends whether the result is a single item or a collection of items.

While the attribute can be accessed and be set like an array it's not an actual array.


$articles = $client->getItems('articles');
// OK
$title = $articles['title'];

$articles = $client->getItems('articles');
// Error
$data = array_merge(['title' => 'Default'], $articles);

Getting the whole response as an array

$articles = $client->getItems('articles');
$articlesArray = $articles->toArray();
// Works
$data = array_merge(['title' => 'Default'], $articlesArray);

Getting the data response

A response include data and metadata, by default interacting with the EntryCollection or Entry you are interacting with the "data" object.

Getting the data as an array

$articles = $client->getItems('articles');
$articlesArray = $articles->getData();


The metadata is another Entry object which wrap the metadata information, it can also access and set data like an array but it's not an array.

Getting the metadata

$articles = $client->getItems('articles');
$metadata = $articles->getMetaData();
$articles = $client->getItems('articles');
$metadataArray = $articles->getMetaData()->getData();


Directus is released under the GPLv3 license. RANGER Studio LLC owns all Directus trademarks and logos on behalf of our project's community. Copyright © 2006-2018, RANGER Studio LLC.

You can’t perform that action at this time.