Initialize the SDK by following either of the methods depending on the type of installation.
Method 1: If installed using Composer
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', 'environment');Method 2: If installed using the zip file
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', 'environment');Once you have initialized the SDK, you can start getting content in your app.
Note: By default, the SDK uses the North American region. Configuration changes are not required for North American region users.
To set the Europe (EU), Azure North America(Azure_NA), Azure Europe (Azure_EU), GCP North America (GCP_NA), or GCP Europe (GCP_EU) region, refer to the code below:
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment', array('region' => ContentstackRegion.<<add_your_region>>));For Setting the Branch.
If you want to initialize SDK in a particular branch use the code given below:
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment', array('region' => Contentstack::Region::<<add_your_region>>, "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.
Get a Single Entry
To get a single entry, you need to specify the content type and the UID of the entry:
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$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:
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$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.
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.
- By default, the limit for response details per request is 100, with the maximum limit set at 250.