Skip to content
Example app for Contentful in PHP
Branch: master
Clone or download
dborsatto Merge pull request #43 from contentful/chore/update-deps
Update dependencies and coding standards
Latest commit 36a90a3 Nov 12, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
bin chore(staging): Set up staging environment Jan 29, 2018
config
docker feat(docker): Add support for Docker (#2) Dec 15, 2017
public
src chore(deps): Update dependencies and coding standards Nov 9, 2018
templates chore(mobile-apps): Enable mobile apps in the modal Aug 24, 2018
tests chore(deps): Update dependencies and coding standards Nov 9, 2018
translations fix(empty-states): Add checks for empty content in templates Mar 8, 2018
.editorconfig feat(project): Implemented new modal, settings page, and diff algorithm Dec 12, 2017
.env.dist
.gitattributes feat(project): Initial commit Dec 6, 2017
.gitignore chore(upgrade): Upgrade to Symfony 4.1 and PHP 7.2 Jun 26, 2018
.php_cs chore(deps): Update dependencies and coding standards Nov 9, 2018
Dockerfile
LICENSE
Procfile
README.md
app.json
composer.json
composer.lock
cypress.json fix(empty-states): Add checks for empty content in templates Mar 8, 2018
docker-compose.yml feat(docker): Add support for Docker (#2) Dec 15, 2017
nginx_app.conf refactor(gzip): Add gzip to heroku config May 2, 2018
phpunit.xml.dist
symfony.lock chore(deps): Update dependencies and coding standards Nov 9, 2018

README.md

The PHP example app

CircleCI

The PHP example app teaches the very basics of how to work with Contentful:

  • consume content from the Contentful Delivery and Preview APIs
  • model content
  • edit content through the Contentful web app

The app demonstrates how decoupling content from its presentation enables greater flexibility and facilitates shipping higher quality software more quickly.

Screenshot of the example app

You can see a hosted version of The PHP example app on Heroku.

What is Contentful?

Contentful provides a content infrastructure for digital teams to power content in websites, apps, and devices. Unlike a CMS, Contentful was built to integrate with the modern software stack. It offers a central hub for structured content, powerful management and delivery APIs, and a customizable web app that enable developers and content creators to ship digital products faster.

Requirements

  • PHP 7.1
  • Git
  • Contentful CLI (only for write access)

Without any changes, this app is connected to a Contentful space with read-only access. To experience the full end-to-end Contentful experience, you need to connect the app to a Contentful space with read and write access. This enables you to see how content editing in the Contentful web app works and how content changes propagate to this app.

Common setup

Clone the repo and install the dependencies.

git clone https://github.com/contentful/the-example-app.php.git
composer install

Steps for read-only access

To start the local server, run the following:

php bin/console server:run

Open http://localhost:8000 and take a look around.

Steps for read and write access (recommended)

Step 1: Install the Contentful CLI.

Step 2: Login to Contentful through the CLI. It will help you to create a free account if you don't have one already.

contentful login

Step 3: Create a new space.

contentful space create --name 'My space for the example app'

Step 4: Seed the new space with the content model. Replace the SPACE_ID with the id returned from the create command executed in step 3.

contentful space seed -s '<SPACE_ID>' -t the-example-app

Step 5: Head to the Contentful web app's API section and grab SPACE_ID, DELIVERY_ACCESS_TOKEN, PREVIEW_ACCESS_TOKEN.

Step 6: Open .env and inject your credentials so it looks like this

// ...
CONTENTFUL_SPACE_ID=<SPACE_ID>
CONTENTFUL_DELIVERY_TOKEN=<DELIVERY_ACCESS_TOKEN>
CONTENTFUL_PREVIEW_TOKEN=<PREVIEW_ACCESS_TOKEN>

Step 7: To start the local server, run the following.

php bin/console server:run

Final Step:

Open http://localhost:8000/?editorial_features=enabled and take a look around. This URL flag adds an “Edit” button in the app on every editable piece of content which will take you back to Contentful web app where you can make changes. It also adds “Draft” and “Pending Changes” status indicators to all content if relevant.

Use Docker

You can also run this app as a Docker container:

Step 1: Clone the repo

git clone https://github.com/contentful/the-example-app.php.git

Step 2: Build the Docker images

docker-compose build

Step 3: Run the Docker containers locally:

docker-compose up

If you created your own Contentful space, you can use it by overriding the following environment variables in the docker-compose file:

environment:
 - CONTENTFUL_SPACE_ID=<SPACE_ID>
 - CONTENTFUL_DELIVERY_TOKEN=<DELIVERY_ACCESS_TOKEN>
 - CONTENTFUL_PREVIEW_TOKEN=<PREVIEW_ACCESS_TOKEN>

Deploy to Heroku

You can also deploy this app to Heroku:

Deploy

You can’t perform that action at this time.