PHP code example of remluben / cockpit-client

1. Go to this page and download the library: Download remluben/cockpit-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

remluben / cockpit-client example snippets


// Set up your basic HTTP client, which makes the HTTP requests to Cockpit under
// the hood.
$http = new GuzzleHttp\Client([
    GuzzleHttp\RequestOptions::TIMEOUT => 2.0, // set an appropriate timeout that suits your application and server needs
    GuzzleHttp\RequestOptions::DEBUG => false, // optionally enable in development mode
]);

// Create an instance of the Cockpit client by passing all ch your first content items, i.e. for content model *faqs*
try {
  $results = $client->contentItems('faqs');
}
catch (\Remluben\CockpitClient\Exceptions\ClientException $e) {
  // A client exception happens whenever 
  // - the HTTP client itself rises an exception
  // - the Cockpit API returns non 2xx status codes or runs into issues
}
catch (\Remluben\CockpitClient\Exceptions\InvalidArgumentException $e) {
  // For unintended method calls, invalid parameters or similar problems the
  // client usually throws this exception 
}

// process your results, if any...
foreach ($results as $item) {
  // do something here...
}