Contentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. Build your application frontend, and Contentstack will take care of the rest. Read More.
Contentstack - PHP Delivery SDK
PHP SDK for Contentstack's Content Delivery API
Prerequisites
To get started with PHP, you will need the following:
- PHP version 5.5.0 or later
SDK installation and setup
To install the PHP SDK, choose either of the following methods:
Method 1: Using Composer
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
Method 2: Downloading the zip file
To download the PHP SDK, perform the following steps:
- Download the PHP SDK.
- Create the dependencies folder in your project directory and move the downloaded .zip file within the dependencies folder.
- Download the MabeEnum class.
- Create a folder named marc-mabe folder inside dependencies, and move the php-enum folder to marc-mabe.
Let's get started with the implementation.
Quickstart in 5 mins
Initialize SDK
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), or GCP North America (GCP_NA) 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"));
Basic Queries
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.
- 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.
Paginating Responses
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.
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->toJSON()->skip(20)->limit(20)->find();
Contentstack
Contentstack abstract class to provide access to Stack Object
Stack
Static method for the Stack constructor
Name | Type | Description |
---|---|---|
api_key (required) | string | API Key of your stack on Contentstack. |
access_token (required) | string | Delivery token of your stack on Contentstack. |
environment (required) | string | Environment from where you want to fetch content. |
config | array |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
ContentstackRegion
Fields
Name | Description |
---|---|
EU | To specify the EU region. |
US | To specify the US region. |
AZURE_NA | To specify the AZURE NA region |
AZURE_EU | To specify the AZURE_EU region |
GCP_NA | To specify the GCP_NA region |
CSException
CSException CSException Class is used to wrap the REST API error
Name | Type | Description |
---|---|---|
error_message | string | Contentstack error message. |
error_code | string | Contentstack Error code |
http_code | int | API http status code |
getErrors
Returns error details of current exception
getStatusCode
To get http status_code of the current exception
Stack
Stack Class to initialize the provided parameter Stack
ContentType
To initialize the ContentType object from where the content will be fetched/retrieved.
Name | Type | Description |
---|---|---|
content_type_uid (required) | string | Valid content type uid relevant to configured stack |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$content_type = $stack->ContentType('content_type_uid');
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$content_types = $stack->ContentType();
Assets
Assets Class to initalize your Assets
Name | Type | Description |
---|---|---|
asset_uid (required) | string | valid asset uid relevent to configured stack |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$assets = $stack->Assets('asset_uid');
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$assets = $stack->Assets();
ImageTrasform
ImageTrasform function is define for image manipulation with different
Name | Type | Description |
---|---|---|
url (required) | string | Image url on which we want to manipulate. |
parameters (required) | object | It is an second parameter in which we want to place different manipulation key and value in array form |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result_url = $stack->ImageTrasform('url', array('quality' => 100));
LivePreviewQuery
To set live preview token and content type uid.
Name | Type | Description |
---|---|---|
parameters (required) | object | Set live preview token and content type uid. |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$stack->LivePreviewQuery(array('live_preview'=> 'token', 'content_type_uid'=? 'content_type_uid', 'entry_uid'=> 'entry_uid'));
getLastActivities
To get the last_activity information of the configured environment from all the content types.
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->getLastActivities();
setHost
To set the host on stack object
Name | Type | Description |
---|---|---|
host (required) | string | Host name/ipaddress from where the content to be fetched |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$stack->setHost('host');
getHost
This function returns host.
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$host = $stack->getHost();
setProtocol
This function sets protocol.
Name | Type | Description |
---|---|---|
protocol (required) | string | Protocol type |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$stack->setProtocol('protocol');
getProtocol
This function return protocol type.
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$protocol = $stack->getProtocol();
setPort
This function sets Port.
Name | Type | Description |
---|---|---|
port (required) | string | Port Number |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$stack->setPort('port');
getPort
This function return Port.
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$port = $stack->getPort();
setAPIKEY
This function sets API Key.
Name | Type | Description |
---|---|---|
api_key (required) | string | Stack API key |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$stack->setAPIKEY('api_key');
getAPIKEY
This function returns API Key.
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$api_key = $stack->getAPIKEY();
setDeliveryToken
This function sets Delivery Token.
Name | Type | Description |
---|---|---|
delivery_token (required) | string | Environment specific delivery token |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$stack->setDeliveryToken('delivery_token');
DeliveryToken
This function returns Delivery Token.
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$token = $stack->DeliveryToken();
setEnvironment
This function sets environment name.
Name | Type | Description |
---|---|---|
environment (required) | string | Name of Environment |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$stack->setEnvironment('environment');
getEnvironment
This function returns environment name.
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$environment = $stack->getEnvironment();
setBranch
This function sets Branch.
Name | Type | Description |
---|---|---|
branch (required) | string | Name of branch |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$stack->setBranch('branch');
Branch
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$branch = $stack->Branch();
getContentTypes
This call returns comprehensive information of all the content types available in a particular stack in your account.
Name | Type | Description |
---|---|---|
params | object | Query params for getting content-type. |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->getContentTypes();
sync
Name | Type | Description |
---|---|---|
param.init | boolean | initializing sync |
param.locale | string | initializing sync with entries of a specific locale |
param.start_date | string | Default: initializing sync with entries published after a specific date |
param.content_type_uid | string | initializing sync with entries of a specific content type |
param.type | string | Use the type parameter to get a specific type of content.Supports 'asset_published', 'entry_published', 'asset_unpublished', 'entry_unpublished', 'asset_deleted', 'entry_deleted', 'content_type_deleted' |
param.pagination_token | string | Fetching the next batch of entries using pagination token |
param.sync_token | string | Performing subsequent sync after initial sync |
For initializing sync:
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->sync({'init'=> true});
For initializing sync with entries of a specific locale:
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->sync({'init'=> true, 'locale'=> 'en-us'});
For initializing sync with entries published after a specific date:
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->sync({'init'=> true, 'start_date'=> '2018-10-22'});
For initializing sync with entries of a specific content type:
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->sync({'init'=> true, 'content_type_uid'=> 'session'});
For initializing sync with specific type:
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->sync({'init'=> true, 'type'=> 'entry_published'});
For fetching the next batch of entries using pagination token:
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->sync({'pagination_token'=> '<page_token>'});
For performing subsequent sync after initial sync:
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->sync({'sync_token'=> '<sync_token>'})
Result
Response as result
get
Get the keys value from the object
Name | Type | Description |
---|---|---|
key (required) | string |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->sync({'init'=> true});
$json = $result->get('key');
toJSON
To convert result object to json
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->sync({'init'=> true});
$json = $result->toJSON();
Assets
Assets refer to all the media files (images, videos, PDFs, audio files, and so on) uploaded in your Contentstack repository for future use.
Name | Type | Description |
---|---|---|
assetUid | string | Uid for asset to be fetch |
Query
Query object to create the "Query" on Assets
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->Assets()->Query()->find;
fetch
Fetch the specified assets
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->Assets('asset_uid')->fetch();
ContentType
ContentType provides Entry and Query instance.
fetch
Fetch the specific content type
Name | Type | Description |
---|---|---|
params | object | Parameters to fetch content |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack-ContentType('content_type_uid')->fetch();
Entry
Entry object to create the "Query" on the specified ContentType
Name | Type | Description |
---|---|---|
uid (required) | string | Entry uid to get details |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$entry = $stack-ContentType('content_type_uid')->Entry('entry_uid');
Query
A query that is used to query for Entry instance.
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$query = $stack-ContentType('content_type_uid')->Query();
Entry
An initializer is responsible for creating Entry object.
Name | Type | Description |
---|---|---|
entryUid | string | Uid for the entry instance. |
contentType | string | ContentType uid for the entry instance. |
language
To set the language code for entry to fetch
Name | Type | Description |
---|---|---|
locale (required) | string | Language code by default is "en-us" |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Entry('entry_uid')->language('en-us')->fetch();
includeContentType
To include content_type along with entries.
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Entry('entry_uid')->includeContentType()->fetch();
includeReferenceContentTypeUID
This method includes the content type UIDs of the referenced entries returned in the response.
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Entry('entry_uid')->includeReferenceContentTypeUID()->fetch();
includeReference
To include reference(s) of other content type in entries
Name | Type | Description |
---|---|---|
field_uids (required) | array | Array of reference field uids. |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Entry('entry_uid')->includeReference(array('categories')))->fetch();
includeEmbeddedItems
To include Embedded Items along with entries and asset.
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Entry('entry_uid')->includeEmbeddedItems()->fetch();
includeBranch
To include branch of publish content.
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Entry('entry_uid')->includeBranch()->fetch();
only
To project the fields in the result set
Name | Type | Description |
---|---|---|
level (required) | string | Level for which field uid to include. Set 'BASE' for top level. |
field_uids (required) | string | field uids as array |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Entry('entry_uid')->toJSON()->only('BASE',array('price'))->fetch();
except
To exclude the fields from the result set.
Name | Type | Description |
---|---|---|
level (required) | string | Level for which field uid to except. Set 'BASE' for top level. |
field_uids (required) | string | field uids as array |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Entry('entry_uid')->toJSON()->except('BASE',array('price'))->fetch();
toJSON
To transform the Result object to server response content
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Entry('entry_uid')-toJSON()->fetch();
fetch
Fetch the specified entry
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Entry('entry_uid')->fetch();
Query
An initializer is responsible for creating Query object.
getQuery
Get the raw/array query from the current instance of Query/Entry.
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$_set = ['vivo', 'samsung', 'redmi 3', 'apple'];
$result = $stack->ContentType('content_type_uid')->Query()->containsIn('title', $_set)->getQuery();
addQuery
Add Query is used to add the raw/array query to filter the entries.
Name | Type | Description |
---|---|---|
query (required) | array | Array formatted query |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$_set = ['vivo', 'samsung', 'redmi 3', 'apple'];
$query1 = $stack->ContentType('content_type_uid_1')->Query()->containsIn('title', $_set)->getQuery();
$result = $stack->ContentType('content_type_uid')->Query()->addQuery($query1)->find();
addParam
To add query parameter in query
Name | Type | Description |
---|---|---|
key (required) | string | Name of key in string |
value (required) | string | Value of the key in string |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->addParam('include_count', 'true')->find();
includeReferenceContentTypeUID
This method includes the content type UIDs of the referenced entries returned in the response.
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->includeReferenceContentTypeUID()->find();
includeContentType
To include content_type along with entries.
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->includeContentType()->find();
includeCount
Retrieve count and data of objects in result.
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->includeCount()->find();
includeBranch
Include branch for publish content.
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->includeBranch()->find();
includeFallback
Include fallback locale publish content, if specified locale content is not publish.
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->includeFallback()->find();
includeEmbeddedItems
Include Embedded Objects (Entries and Assets) along with entry/entries details.
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->includeEmbeddedItems()->find();
includeReference
Add a constraint that requires a particular reference key details.
Name | Type | Description |
---|---|---|
field_uids (required) | array | Array of reference field uids |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->includeReference(array('reference_uid_1', 'reference_uid_2'))->find();
regex
Add a regular expression constraint for finding string values that match the provided regular expression.
Name | Type | Description |
---|---|---|
key (required) | string | The key to be constrained. |
regex (required) | string | The regular expression pattern to match. |
modifiers | string | Any of the following supported Regular expression modifiers.
|
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->regex('name', '^browser')->find();
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->regex('name', '^browser', 'i')->find();
language
To set the language code in the query
Name | Type | Description |
---|---|---|
lang (required) | string | Language code to get entries form stack |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->language('en-us')->find();
tags
Include tags with which to search entries.
Name | Type | Description |
---|---|---|
tags (required) | array | Array of tags you want to match in the entries |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->tags(array('tag1', 'tag2'))->find();
limit
A limit on the number of objects to return.
Name | Type | Description |
---|---|---|
limit (required) | int | No of objects to limit. |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->limit(20)->find();
skip
The number of objects to skip before returning any.
Name | Type | Description |
---|---|---|
skip (required) | int | No of objects to skip. |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->skip(20)->find();
ascending
Sort the results in ascending order with the given key.
Name | Type | Description |
---|---|---|
field_uid (required) | string | The key to order by. |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->ascending('name')->find();
descending
Sort the results in descending order with the given key.
Name | Type | Description |
---|---|---|
field_uid (required) | string | The key to order by. |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->descending('name')->find();
logicalOR
Combines all the queries together using OR operator
Name | Type | Description |
---|---|---|
queries (required) | array | Array of Query instances on which OR query executes. |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$query1 = $stack->ContentType('content_type_uid_1')->Query()->where('title', 'Redmi Note 3');
$query2 = $stack->ContentType('content_type_uid_1')->Query()->where('color', 'Gold');
$result = $stack->ContentType('content_type_uid')->Query()->logicalOr(array($query1, $query2))->find();
logicalAND
Combines all the queries together using AND operator
Name | Type | Description |
---|---|---|
queries (required) | array | Array of Query instances on which AND query executes. |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$query1 = $stack->ContentType('content_type_uid_1')->Query()->where('title', 'Redmi Note 3');
$query2 = $stack->ContentType('
')->Query()->where('color', 'Gold');
$result = $stack->ContentType('content_type_uid')->Query()->logicalAND(array($query1, $query2))->find();
except
Specifies list of field uids that would be excluded from the response.
Name | Type | Description |
---|---|---|
level (required) | string | Level for field uid |
field_uid (required) | array | Field uid which get excluded from the response. |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->except('BASE',array('price'))->find();
exists
Add a constraint that requires, a specified key does exists in response.
Name | Type | Description |
---|---|---|
field_uid (required) | string | Field uid against the value not existence is checked |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->exists('age')->find();
notExists
Add a constraint that requires, a specified key does not exists in response.
Name | Type | Description |
---|---|---|
field_uid (required) | string | Field uid against the value not existence is checked |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->notExists('age')->find();
where
Query the field which has exact value as specified
Name | Type | Description |
---|---|---|
field (required) | string | Field in the entry against which comparison needs to be done. |
value (required) | string | Value against which comparision is going to happen |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->where('age', '20')->find();
notEqualTo
Query the field which has not equal to value than specified one
Name | Type | Description |
---|---|---|
field (required) | string | Field in the entry against which comparison needs to be done. |
value (required) | string | Value against which comparision is going to happen |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->notEqualTo('age', '20')->find();
containedIn
Query the field value from the given set of values
Name | Type | Description |
---|---|---|
field (required) | string | Field in the entry against which comparison needs to be done. |
value (required) | string | Array value against which comparison is going to happen |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->containedIn("field_uid", ["Christmas Deal", "Summer Deal"])->find();
notContainedIn
Query the field value other than the given set of values
Name | Type | Description |
---|---|---|
field (required) | string | Field in the entry against which comparison needs to be done. |
value (required) | string | Array value against which comparison is going to happen |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->notContainedIn("field_uid", ["Christmas Deal", "Summer Deal"])->find();
lessThan
Query the field which has less value than specified one
Name | Type | Description |
---|---|---|
field (required) | string | Field in the entry against which comparison needs to be done. |
value (required) | string | Value against which comparison is going to happen |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->lessThan('age', 20)->find();
lessThanEqualTo
Query the field which has less or equal value than specified one
Name | Type | Description |
---|---|---|
field (required) | string | Field in the entry against which comparison needs to be done. |
value (required) | string | Value against which comparison is going to happen |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->lessThanEqualTo('age', 20)->find();
greaterThan
Query the field which has greater value than specified one
Name | Type | Description |
---|---|---|
field | string | Field in the entry against which comparison needs to be done. |
value (required) | string | Value against which comparison is going to happen |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->greaterThan('age', 20)->find();
greaterThanEqualTo
Query the field which has greater or equal value than specified one.
Name | Type | Description |
---|---|---|
field (required) | string | Field in the entry against which comparision needs to be done |
value (required) | string | Value against which comparision is going to happen |
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->greaterThanEqualTo('age', 20)->find();
find
Get all entries based on the specified subquery
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->find();
count
To get only count result
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->count()->find();