GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - erik-perri/contentstack-php: PHP SDK for Contentstack - Content Delivery API

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

653 Commits
653 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
examples
examples
 
 
src
src
 
 
test
test
 
 
.gitignore
.gitignore
 
 
.talismanrc
.talismanrc
 
 
CHANGELOG.md
CHANGELOG.md
 
 
CODEOWNERS
CODEOWNERS
 
 
LICENSE.txt
LICENSE.txt
 
 
README.md
README.md
 
 
SECURITY.md
SECURITY.md
 
 
composer.json
composer.json
 
 
composer.lock
composer.lock
 
 
config.php
config.php
 
 
phpunit.xml
phpunit.xml
 
 

Repository files navigation

Contentstack

PHP SDK for Contentstack

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 provides PHP SDK to build application on top of PHP. Given below is the detailed guide and helpful resources to get started with our PHP SDK.

Prerequisite

You need PHP version >= 5.5.0 or later installed to use the Contentstack PHP SDK.

Setup and Installation

Install the library using Composer:

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

composer require contentstack/contentstack

To initialize the SDK, you will need to specify the API Key, Delivery Token, and Environment Name of your stack.

use Contentstack\Contentstack;
$stack = Contentstack::Stack(API_KEY, DELIVERY_TOKEN, ENV_NAME);

For Setting the European Region: If you want to set and use European region, refer to the code below:

use Contentstack\Contentstack;
use Contentstack\ContentstackRegion;
$stack = Contentstack::Stack(API_KEY, DELIVERY_TOKEN, ENV_NAME, array('region'=> ContentstackRegion.EU));

Download and install library:

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

  1. Download the PHP SDK
  2. Create dependencies folder in your project directory
  3. Move this downloaded zip file to a dependencies folder
  4. Download the MabeEnum
  5. Create marc-mabe folder inside the dependencies folder
  6. Move the php-enum folder inside the marc-mabe folder

To initialize the SDK, you will need to 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);

Key Concepts for using Contentstack

Stack

A stack is like a container that holds the content of your app. Learn more about Stacks.

Content Type

Content type lets you define the structure or blueprint of a page or a section of your digital property. It is a form-like page that gives Content Managers an interface to input and upload content. Read more.

Entry

An entry is the actual piece of content created using one of the defined content types. Learn more about Entries.

Asset

Assets refer to all the media files (images, videos, PDFs, audio files, and so on) uploaded to Contentstack. These files can be used in multiple entries. Read more about Assets.

Environment

A publishing environment corresponds to one or more deployment servers or a content delivery destination where the entries need to be published. Learn how to work with Environments.

Contentstack PHP SDK: 5-minute Quickstart

Initializing your SDK

Install the library using Composer:

composer require contentstack/contentstack

To initialize the SDK, you will need to 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 get the API credentials mentioned above, log in to your Contentstack account and then in your top panel navigation, go to Settings > Stack to view the API Key and Delivery Token.

Querying content from your stack

To find all entries of a content type, use the query given below:

$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

To fetch a specific entry from a content type, use the following query:

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

Advanced Queries

You can query for content types, entries, assets and more using our PHP API Reference.

PHP API Reference Doc

Working with Images

We have introduced Image Delivery APIs that let you retrieve images and then manipulate and optimize them for your digital properties. It lets you perform a host of other actions such as crop, trim, resize, rotate, overlay, and so on.

For example, if you want to crop an image (with width as 300 and height as 400), you simply need to append query parameters at the end of the image URL, such as, https://images.contentstack.io/v3/assets/blteae40eb499811073/bltc5064f36b5855343/59e0c41ac0eddd140d5a8e3e/download?crop=300,400. There are several more parameters that you can use for your images.

Read Image Delivery API documentation.

You can use the Image Delivery API functions in this SDK as well. Here are a few examples of its usage in the SDK.

// set the image quality to 100.

$imageUrl = $stack->imageTransform(imageUrl, array('quality' => 100));

// resize the image by specifying width and height.

$imageUrl = $stack->imageTransform(imageUrl, array(
  'width' => 100,
  'height' => 100
));

// enable auto optimization for the image.

$imageUrl = $stack->imageTransform(imageUrl, array('auto' => 'webp'));

Helpful Links

  • Contentstack Website
  • Official Documentation
  • Content Delivery API Docs

About

PHP SDK for Contentstack - Content Delivery API

Resources

Readme
License

Security policy

Security policy
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.