Get Started with PHP SDK

This guide will help you get started with Contentstack PHP SDK to build apps powered by Contentstack.

Prerequisites

To get started with PHP, you will need the following:

  • PHP version 5.5.0 or later

SDK Installation and Setup

To use the PHP SDK, you need to perform the following steps:

  1. Download/clone the PHP SDK.
  2. Paste the downloaded ZIP file of the PHP SDK to a folder of your choice.

Let's get started with the implementation.

Initialize SDK

To initialize the SDK, specify the stack’s API keydelivery token, and name of the environment where you will publish the content.

use Contentstack\Contentstack;
include_once "contentstack/index.php";
$stack = Contentstack::Stack(API_KEY, DELIVERY_TOKEN, ENV_NAME);

Once you have initialized the SDK, you can start getting content in your app.

Basic Queries

Get a Single Entry

To get a single entry, you need to specify the content type and the UID of the entry:

$result = $stack->ContentType(CONTENT_TYPE_UID)->Entry(ENTRY_UID)->toJSON()->fetch()
$result - entry object

Get Multiple Entries

To retrieve multiple entries of a content type, specify the content type uid. You can also specify search parameters to filter results:

$result = $stack->ContentType(CONTENT_TYPE_UID)->Query()->toJSON()->includeCount()->includeContentType()->find()
$result[0] - array of entries
$result[1] - content type
$result[2] - count of the entries

These were examples of some of the basic queries of the SDK. For advanced queries, refer to the Contentstack PHP SDK API reference.

More articles in "Use PHP SDK"

On This Page

top-arrow