Skip to content

kontent-ai/sample-app-php

 
 

Repository files navigation

Important

This sample app relies on the Dancing Goat project, which is no longer available for creation in Kontent.ai.

If you still wish to use this project, you can import the Dancing Goat project using the Data Ops tool by following the instructions provided in our Dancing Goat repository.

Kontent.ai sample Laravel PHP web application

Stack Overflow Discord

This is a sample website written in PHP 7 using Laravel framework and Kontent.ai Delivery SDK for PHP. You can register your Kontent account for free at https://app.kontent.ai.

Application setup

Before you can run the app, make sure your environment is set up correctly with PHP 8+ and the Composer package manager installed.

Once these prerequisites are met, you can run the application as follows:

  1. Clone this repository.
  2. In your command line, navigate to the project folder.
  3. Run composer install to install dependencies.
  4. (Optional) Run composer run prepare-environment to create a sample Laravel environment file.
  5. Run php artisan serve to run the sample app.

The app is now running locally at 127.0.0.1:8000 (default) and you can open it in your browser.

Alternatively, you can also deploy your application to your Apache server by cloning the repository, running composer install, and accessing corresponding address on your server.

Connecting your project

This sample website displays content from a Sample Project that demonstrates Kontent.ai features and best practices. This fully featured project contains marketing content for Dancing Goat – an imaginary chain of coffee shops. By default, this sample website uses a shared project where the content remains constant for everyone.

You can change the source Kontent.ai project to your own project to be able to change the content. If you don't have your own Sample Project, any admin of a Kontent.ai subscription can generate one.

When you have a Sample Project, follow these steps to connect it to this sample app:

  1. In Kontent.ai, choose Project settings from the app menu.
  2. Under Development, choose API keys.
  3. Copy your Project ID.
  4. Set you PROJECT_ID environment variable - most probably in .env file
  5. Save the .env file and restart the server.

Now when you run the sample application, content is retrieved from your project.

Compile resources

If you want to adjust CSS and Javascript file, you need to rebuild them.

First you need to install yarn and install dependencies by running following command in repository root.

yarn

Development compilation

For development purposes you want to turn on development mode of compilation wit hot-reload capabilities.

yarn watch // or `yarn dev` for single development compilation

Production compilation

Tor production compilation, run:

yarn prod

Content administration

  1. Navigate to https://app.kontent.ai in your browser.
  2. Sign in with your credentials.
  3. Manage content in the content administration interface of your sample project.

You can learn more about content editing with in the Kontent.ai Learn portal.

Content delivery

You can retrieve content either through the Kontent.ai Delivery SDKs or the Kontent.ai Delivery API:

  • For published content, use https://deliver.kontent.ai/PROJECT_ID/items.
  • For unpublished content, use https://preview-deliver.kontent.ai/PROJECT_ID/items.

For more info about the API, see the API reference.

You can find the Delivery and other SDKs at Kontent.ai Github Organization.

Feedback & Contributing

Check out the contributing page to see the best places to file issues, start discussions, and begin contributing.

Author

We would like to express our thanks to Stephen Rushing who created this sample application.