This guide will help you get started with Contentstack PHP SDK to build apps powered by Contentstack.
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:
- Download/clone the PHP SDK.
- Paste the downloaded ZIP file of the PHP SDK to a folder of your choice.
Let's get started with the implementation.
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.
Get a Single 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 - array of entries $result - content type $result - 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.