1. Go to this page and download the library: Download gentics/mesh-php-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/ */
gentics / mesh-php-client example snippets
use Gentics\Mesh\Client\MeshClient;
calhost:8080/api/v1");
// Load user info (sync)
$request = $client->me();
$response = $request->send();
echo $response->getBody();
// Load user info (async)
$promise = $request->sendAsync();
$promise->then(function ($response) {
echo 'I completed! ' . $response->getBody();
});
$promise->wait();
// Load users and apply paging
$request = $client->findUsers(["perPage" => 1]);
$response = $request->send();
echo $response->getBody();
$client = new MeshClient("http://localhost:8080/api/v1");
// You can either login and use the build-in cookie handling
// Keep in mind that your cookie will not be automatically refreshed.
// Any authenticated request will refresh the cookie and keep you authenticated.
$client->login("admin", "admin")->wait();
// Or use a dedicated API key which will never expire
// You can use the mesh-cli to generate a key
// Setting the API key will invalidate any previously set login token information
$client->setAPIKey("eyJ0eXAiOiJKV1QiLC … ZYYJbD8HllF6XZT0xRTxr3i4b9PY");
$client = new MeshClient("http://localhost:8888/api/v1");
$request = $client->webroot("demo", "/images/yacht-pelorus.jpg");
$response = $request->send();
// You can check whether the webroot response returns json or otherwise binary data (e.g. image data)
$response->isJson();
$client = new MeshClient("http://localhost:8080/api/v1");
$client->login("admin", "admin")->wait();
// 1. Create User
$request = [
"username" => "guzzle",
"password" => "geheim",
];
$uuid = "5725992507e748a1a5992507e7f8a115";
$userResp = $client->createUserWithUuid($uuid, $request)->send()->toJson();
// 2. Read user
$user = $client->findUserByUuid($uuid)->send()->toJson();
// 3. Update user
$user->username = "hugo";
$updated = $client->updateUser($uuid, $user)->send()->toJson();
// 4. Delete user
$client->deleteUser($uuid)->send();