Was this article helpful?
Thanks for your feedback
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:
To install the PHP SDK, choose either of the following methods:
To install the PHP SDK in your project using Composer, fire up the terminal, point it to the project location, and run the following command:
composer require contentstack/contentstack
To download the PHP SDK, perform the following steps:
Let's get started with the implementation.
Initialize the SDK by following either of the methods depending on the type of installation.
To initialize the SDK, specify the API Key, delivery token, and environment name of your stack.
use Contentstack\Contentstack; $stack = Contentstack::Stack(API_KEY, DELIVERY_TOKEN, ENV_NAME);
To initialize the SDK, specify the API key, delivery token, and environment name of your stack.
include_once __DIR__ . '/dependencies/contentstack/index.php'; use Contentstack\Contentstack; $stack = Contentstack::Stack(API_KEY, DELIVERY_TOKEN, ENV_NAME);
Once you have initialized the SDK, you can start getting content in your app.
For Setting the branch:
If you want to initialize SDK in a particular branch use the code given below:
static Stack = Contentstack::Stack('api_key', 'delivery_token', 'environment_name', array("region"=> Contentstack::Region::US, "branch"=> "branch"))
Contentstack SDKs let you interact with the Content Delivery APIs and retrieve content from Contentstack. They are read-only in nature. The SDKs fetch and deliver content from the nearest server via Fastly, our powerful and robust CDN.
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
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.
Note: Currently, the PHP SDK does not support multiple content types referencing in a single query. For more information on how to query entries and assets, refer the Queries section of our Content Delivery API documentation.
In a single instance, the Get Multiple Entries query will retrieve only the first 100 items of the specified content type. You can paginate and retrieve the rest of the items in batches using the limit parameters in subsequent requests.
$stack = Contentstack::Stack(API_KEY, DELIVERY_TOKEN, ENV_NAME); $result = $stack->ContentType(CONTENT_TYPE_UID)->Query()->toJSON()->skip(20)->limit(20)->find()
Was this article helpful?
Thanks for your feedback