# Cheatsheet connect getcockpit with vanilla PHP

**URL:** <https://discourse.getcockpit.com/t/cheatsheet-connect-getcockpit-with-vanilla-php/2120>\
**Category:** General\
**Created:** [October 26, 2021, 4:48am UTC](https://discourse.getcockpit.com/t/cheatsheet-connect-getcockpit-with-vanilla-php/2120 "2021-10-26T04:48:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![creativeplusplus](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/creativeplusplus/32/844_2.png) [@creativeplusplus](https://discourse.getcockpit.com/u/creativeplusplus)\
**Post date:** [October 26, 2021, 4:48am UTC](https://discourse.getcockpit.com/t/cheatsheet-connect-getcockpit-with-vanilla-php/2120/1 "2021-10-26T04:48:09Z")

</div>

Put Cockpit folder in same directory

- project Folder  
– cockpit  
– post-detail.php  
– posts.php  
– contact.php

posts.php

```auto
<?php
require_once('./cockpit/bootstrap.php');
$limit = 5;

    $posts = cockpit('collections')->find('posts', [
        'filter' => ['published' => true],
        'limit' => $limit,
        'sort' => ['_o' => -1],
    ]);

foreach ($posts as $post) { ?>
<h1><?=$post['title']?></h1>
<p><?=$post['content']?></p>
<?php } ?>

```

contact.php

add data to form

```auto
<?php
require_once('./cockpit/bootstrap.php');

if($isset($_POST["btnSubmit"])){
        $params = [];
        $data = array(
            "fullname" => $_POST['fullname'],
            "companyname" => $_POST['companyname'],
            "email" => $_POST['email'],
            "phone" => $_POST['phone'],
            "message" => $_POST['message']
        );
        cockpit('forms')->submit('contactform', $data, $params);
}else{

}
?>
<form>
...
</form>

```

post\_detail.php

```auto
<?php
require_once('./cockpit/bootstrap.php');

$post = cockpit('collections')->find('posts', [
    'filter' => ['title_slug' => 'blog-1', 'published' => true]
]);
$post = $post[0];
?>
<h1><?=$post['title']?></h1>
<p><?=$post['content']?></p>

```

Singleton

```auto
$settings = cockpit('singletons')->getData('general_settings');
//you can see the settings array

print_r($settings)

```

Navigation.php

```auto
//return tree array dont forget active custom sortable entries in collection

![Screen Shot 2021-10-26 at 12.15.15|617x500](upload://eSkGTutZ3RmzYkOrEzoMcIo6iKZ.png)

$navs = cockpit('collections')->find('menu', [
	'limit' => 100,
    'buildtree' => true
]);

```

For User in cokcpit only via API

```auto
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://domain.com/api/cockpit/listUsers?token=XXXX");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$users = curl_exec($curl);
curl_close($curl);

      $json = json_decode($users);
      foreach ($json as $user) {
echo $user->email;
echo $user->id
      
      }

```

You can see the All function:  
Collections  
cockpit/modules/Collections/bootstrap

Form  
cockpit/modules/Forms/bootstrap

Singleton  
cockpit/modules/Singletons/bootstrap

---

<div class="post-metadata">

**Author:** ![MarcTabaries](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/marctabaries/32/867_2.png) [@MarcTabaries](https://discourse.getcockpit.com/u/MarcTabaries)\
**Post date:** [October 31, 2021, 8:54am UTC](https://discourse.getcockpit.com/t/cheatsheet-connect-getcockpit-with-vanilla-php/2120/2 "2021-10-31T08:54:19Z")

</div>

You can also use Guzzle (to fetch data via Cockpit API) and Slim (micro-framework, to manage the routing part) to do this :

- Guzzle tutorial : [https://artisansweb.net/use-guzzle-php-http-client-sending-http-requests](https://artisansweb.net/use-guzzle-php-http-client-sending-http-requests)

- Guzzle doc : [https://docs.guzzlephp.org/en/stable](https://docs.guzzlephp.org/en/stable)

- Slim tutorial : [https://odan.github.io/2019/11/05/slim4-tutorial.html](https://odan.github.io/2019/11/05/slim4-tutorial.html)

- Slim doc : [https://www.slimframework.com/docs/v4](https://www.slimframework.com/docs/v4)

😉

---

<div class="post-metadata">

**Author:** ![Sebastian](https://avatars.discourse-cdn.com/v4/letter/s/4da419/32.png) [@Sebastian](https://discourse.getcockpit.com/u/Sebastian)\
**Post date:** [February 19, 2022, 3:22pm UTC](https://discourse.getcockpit.com/t/cheatsheet-connect-getcockpit-with-vanilla-php/2120/3 "2022-02-19T15:22:34Z")

</div>

Hi [creativeplusplus](https://discourse.getcockpit.com/u/creativeplusplus), how did you manage the routing of the pages and the rewriting of the url of the jobs?  
Thanks if you want to answer me.

---

<div class="post-metadata">

**Author:** ![seank1968](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/seank1968/32/1002_2.png) [@seank1968](https://discourse.getcockpit.com/u/seank1968)\
**Post date:** [February 21, 2022, 2:12pm UTC](https://discourse.getcockpit.com/t/cheatsheet-connect-getcockpit-with-vanilla-php/2120/4 "2022-02-21T14:12:14Z")

</div>

@creativeplusplus Only recently found Cockpit and in the middle of my first site - this post has been incredibly helpful!!

Many thanks!
