Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alantiller/directus-php-sdk
The PHP SDK for Directus 9
https://github.com/alantiller/directus-php-sdk
Last synced: about 2 months ago
JSON representation
The PHP SDK for Directus 9
- Host: GitHub
- URL: https://github.com/alantiller/directus-php-sdk
- Owner: alantiller
- License: mit
- Created: 2021-03-09T23:47:16.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-04-08T19:05:19.000Z (over 1 year ago)
- Last Synced: 2024-04-25T10:41:48.976Z (9 months ago)
- Language: PHP
- Homepage:
- Size: 50.8 KB
- Stars: 26
- Watchers: 3
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-directus - PHP SDK - PHP SDK to provide easy access to the Directus API. (Integration / Community)
README
# Directus PHP SDK
The PHP SDK for Directus 9 (@directus/directus)
# Documentation
## Installation (Composer)
We're now on packagist!!! Making installation even easier, all you have to do is include our package `alantiller/directus-php-sdk` in your `composer.json` file `^1.0` for the version and then run composer update.
Or you can run `composer require alantiller/directus-php-sdk` and that will do all of the above for you :)
## Installation (Manual)
To install the Directus PHP SDK is super simple and easy. All you need to do is download the latest release from the releases page and place the PHP file in your
## Usage
We've simplified the way you create a newinstance of the SDK, now you set the config settings in the construct rather than another function. You can still define the other variables as before in the construct as below.
```
base_url;
```## Items
### Create a Single Item
```
$directus->create_items('articles', array(
"status" => "draft",
"title" => "example",
"slug" => "example"
));
```### Read All Items
```
$directus->get_items('articles');
```### Read By Query
```
$directus->get_items('articles', array(
search => "",
filter => array(
"date_published" => array(
"_gte" => "\$NOW" // If you use Directus provided dynamic options like $NOW make sure you ascape the item \$NOW so PHP knows it's not a PHP variable
)
)
));
```### Read By Primary Key
```
$directus->get_items('articles', 15);
```### Update Single Item
```
$directus->update_items('articles', array("title" => "example_new"), 15);
```### Delete an Item(s)
```
// One
$directus->delete_items('articles', 15);// Multiple
$directus->delete_items('articles', array(15, 42));
```## Auth
### Get / Set Token
Setting a static auth token, if someone authenticates their authentication will override this auth token!
```
$directus->auth_token('abc.def.ghi');$directus->auth_token;
```### Login
When you submit a login request it will either respone with en error "errors" or it will just return true. If it has returned try then the login was successful and the Auth has been stored using the method defined in the config (_SESSION by default). The login with AutoRefresh so you will not need to worry about the token expiring.
```
$directus->auth_user('[email protected]', 'Pa33w0rd');
```### Refresh
By default the SDK will auto refresh every fifteen minuites so the token is never expired. We will add the ability to turn off autoRefresh in the future.
### Logout
```
$directus->auth_logout();
```### Request a Password Reset
The second value is optional if you want to sent a custom return URL for the reset email.
```
$directus->auth_password_request('[email protected]', 'https://example.com/comfirm');
```### Reset a Password
Note: the token passed in the first parameter is sent in an email to the user when using `auth_password_request`
```
$directus->auth_password_reset('abc.def.ghi', 'N3wPa33W0rd');
```