# Cockpit implementation in PHP application

**URL:** <https://discourse.getcockpit.com/t/cockpit-implementation-in-php-application/619>\
**Category:** Support\
**Created:** [February 27, 2019, 10:43pm UTC](https://discourse.getcockpit.com/t/cockpit-implementation-in-php-application/619 "2019-02-27T22:43:54Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![gstar](https://avatars.discourse-cdn.com/v4/letter/g/ce73a5/32.png) [@gstar](https://discourse.getcockpit.com/u/gstar)\
**Post date:** [February 27, 2019, 10:43pm UTC](https://discourse.getcockpit.com/t/cockpit-implementation-in-php-application/619/1 "2019-02-27T22:43:54Z")

</div>

I’m aware that headless CMSs such as Cockpit are designed to be used over a variety of platforms (not just websites), but let me explain my specific scenario.

I currently develop websites primarily in monolithic frameworks such as WordPress. I now wish to replace this with Cockpit. At present, the websites that I want to develop are just simple brochure websites - so their content will most likely never be consumed on other platforms.

I want to know what is the best way I should implement Cockpit in my websites? For the front end I will use a custom built PHP framework, or maybe Laravel in some cases. So I guess I could use something like Guzzle for the API calls.

My idea is to place Cockpit in a subfolder of the website structure, and so my clients can access the CMS by going to `/cms`.

Is there anything wrong with this approach? Is there a better way to do it?

---

<div class="post-metadata">

**Author:** ![artur](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/artur/32/4_2.png) [@artur](https://discourse.getcockpit.com/u/artur)\
**Post date:** [February 27, 2019, 11:43pm UTC](https://discourse.getcockpit.com/t/cockpit-implementation-in-php-application/619/2 "2019-02-27T23:43:22Z")

</div>

Hi!

this is totally possible. Just add cockpit in a subfolder and the only thing you have to do is to

`include 'cockpitfolder/bootstrap.php'`

anywhere in your code to get full access to the cockpit api.

e.g. to get all posts of the posts collection:

```auto
$posts = cockpit('collections')->find('posts', [
   'filter' => ['published' => true],
   'limit' => 10
]);

```

---

<div class="post-metadata">

**Author:** ![gstar](https://avatars.discourse-cdn.com/v4/letter/g/ce73a5/32.png) [@gstar](https://discourse.getcockpit.com/u/gstar)\
**Post date:** [February 27, 2019, 11:53pm UTC](https://discourse.getcockpit.com/t/cockpit-implementation-in-php-application/619/3 "2019-02-27T23:53:24Z")

</div>

Excellent. So am I right in assuming I would need to include the Cockpit subfolder in my Git repository?

---

<div class="post-metadata">

**Author:** ![gstar](https://avatars.discourse-cdn.com/v4/letter/g/ce73a5/32.png) [@gstar](https://discourse.getcockpit.com/u/gstar)\
**Post date:** [February 28, 2019, 9:54am UTC](https://discourse.getcockpit.com/t/cockpit-implementation-in-php-application/619/4 "2019-02-28T09:54:45Z")

</div>

One more question. What is the best way to create “pages” for a website? So let’s say I want to build a 5 page website (home, about, services, service details, contact). I want my client to go in the CMS, click the page and be able to edit the content. Each page has the following fields:

- Title (SEO)
- Description (SEO)
- Heading
- Sub heading
- Banner image
- Content

However some pages will also contain some specific fields, e.g. on the Contact page there will be a field to enter Google Maps embed code.

Now I think the closest thing to achieve this in Cockpit is “Singletons”. The only issue with this is that I would have to create the fields repeatedly for each page. Is there a way to have a singleton which extends a “base” singleton, which contains all of the above fields?

---

<div class="post-metadata">

**Author:** ![gstar](https://avatars.discourse-cdn.com/v4/letter/g/ce73a5/32.png) [@gstar](https://discourse.getcockpit.com/u/gstar)\
**Post date:** [May 14, 2019, 10:32pm UTC](https://discourse.getcockpit.com/t/cockpit-implementation-in-php-application/619/5 "2019-05-14T22:32:16Z")

</div>

Anyone able to advise on my last 2 posts?

---

<div class="post-metadata">

**Author:** ![pauloamgomes](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/pauloamgomes/32/48_2.png) [@pauloamgomes](https://discourse.getcockpit.com/u/pauloamgomes)\
**Post date:** [May 15, 2019, 9:07pm UTC](https://discourse.getcockpit.com/t/cockpit-implementation-in-php-application/619/6 "2019-05-15T21:07:13Z")

</div>

You can have a page content composed by the fields you described:

- Title - textfield (can be used to generate also the page slug)
- Description - textarea (limited to 155 chars), you may use it in your FE also for og and twitter card description
- Banner - asset (don’t use image field but asset instead, you can take a look on the imagestyles addon to have images automatically resized for your fe)
- Content - my suggestion is to use the LayoutComponents module and use the core components or build your own, it results in a better user experience and you can handle them better in the fe. That will also help with the specific aspects of each page like the google map embed code.

---

<div class="post-metadata">

**Author:** ![gstar](https://avatars.discourse-cdn.com/v4/letter/g/ce73a5/32.png) [@gstar](https://discourse.getcockpit.com/u/gstar)\
**Post date:** [May 15, 2019, 10:32pm UTC](https://discourse.getcockpit.com/t/cockpit-implementation-in-php-application/619/7 "2019-05-15T22:32:30Z")

</div>

Hey, thanks for your reply.

So just to clarify, do I create “pages” as a collection or singleton?

And secondly how do I include a LayoutComponent? I have managed to create one but I cannot work out how to include it as a field.

EDIT: I think I’ve figured this out. Thanks for your help!

---

<div class="post-metadata">

**Author:** ![pauloamgomes](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/pauloamgomes/32/48_2.png) [@pauloamgomes](https://discourse.getcockpit.com/u/pauloamgomes)\
**Post date:** [May 16, 2019, 9:33am UTC](https://discourse.getcockpit.com/t/cockpit-implementation-in-php-application/619/8 "2019-05-16T09:33:36Z")

</div>

Contents that may have many entries (e.g. pages, taxomies, etc…) should be on Collections, Singletons are for a different purpose (you can use it for storing settings, blocks of data, etc…).

To use core components you only need to create a field of type Layout in your collection.  
If you want to build your own components you need [https://github.com/agentejo/LayoutComponents](https://github.com/agentejo/LayoutComponents) addon (and then go to settings / layout components)

---

<div class="post-metadata">

**Author:** ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)\
**Post date:** [May 19, 2019, 8:56pm UTC](https://discourse.getcockpit.com/t/cockpit-implementation-in-php-application/619/9 "2019-05-19T20:56:48Z")

</div>

@gstar If you build a PHP app, maybe Monoplane is interesting for you. I solved a lot of edge cases already and it is based on the same structure, like you suggested. I use it with one collection named “pages” and one singleton named “config” and a handful of custom controllers for different collections, forms etc.

> **[raffaelj/Monoplane](https://github.com/raffaelj/Monoplane)**
>
> first proof of concept for CpMultiplane - not maintained anymore - raffaelj/Monoplane

---

<div class="post-metadata">

**Author:** ![TheComputerM](https://avatars.discourse-cdn.com/v4/letter/t/8c91f0/32.png) [@TheComputerM](https://discourse.getcockpit.com/u/TheComputerM)\
**Post date:** [November 22, 2019, 3:11pm UTC](https://discourse.getcockpit.com/t/cockpit-implementation-in-php-application/619/10 "2019-11-22T15:11:48Z")

</div>

Can you guide me to documentation of the bootstrap.php and how to get singletons using it?

---

<div class="post-metadata">

**Author:** ![dosi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/dosi/32/451_2.png) [@dosi](https://discourse.getcockpit.com/u/dosi)\
**Post date:** [December 6, 2019, 5:08am UTC](https://discourse.getcockpit.com/t/cockpit-implementation-in-php-application/619/11 "2019-12-06T05:08:21Z")

</div>

Hey @artur, is there any documentation with examples? Because the documentation on the website is very short and does not help much. 😭

---

<div class="post-metadata">

**Author:** ![dosi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/dosi/32/451_2.png) [@dosi](https://discourse.getcockpit.com/u/dosi)\
**Post date:** [May 1, 2021, 7:05am UTC](https://discourse.getcockpit.com/t/cockpit-implementation-in-php-application/619/12 "2021-05-01T07:05:31Z")

</div>

Too bad. Over a year and no response…
