Skip to content

Repository files navigation

microCMS PHP SDK

microCMS のPHP SDKです。

保守方針

このSDKの現在の保守レベルは Maintenance です。

詳細はSDKの保守方針をご覧ください。

チュートリアル

公式チュートリアルをご覧ください。

インストール

$ composer require microcmsio/microcms-php-sdk

使い方

インポート

<?phprequire_once('vendor/autoload.php');
use \Microcms\Client;

クライアントオブジェクトの作成

$client = newClient(
"YOUR_DOMAIN", // YOUR_DOMAINはXXXX.microcms.ioのXXXXの部分です"YOUR_API_KEY"// APIキー
);

コンテンツ一覧の取得

$list = $client->list("endpoint");
echo$list->contents[0]->title;

パラメータを指定したコンテンツ一覧の取得

$list = $client->list("endpoint", [
"draftKey" => "foo",
"limit" => 10,
"offset" => 1,
"orders" => ["createdAt", "-updatedAt"],
"q" => "こんにちは",
"fields" => ["id", "title"],
"filters" => "title[contains]microCMS",
"depth" => 1
]);
echo$list->contents[0]->title;

単一コンテンツの取得

$object = $client->get("endpoint", "my-content-id");
echo$object->title;

パラメータを指定した単一コンテンツの取得

$object = $client->get("endpoint", "my-content-id", [
"draftKey" => "foo",
"fields" => ["id", "title"],
"depth" => 1,
]);
echo$object->title;

オブジェクト形式のコンテンツの取得

$object = $client->get("endpoint");
echo$object->title;

コンテンツの作成

$createResult = $client->create(
"endpoint",
[
"title" => "コンテンツ",
"contents" => "こんにちは、コンテンツ!"
]
);
echo$createResult->id;

IDを指定したコンテンツの作成

$createResult = $client->create(
"endpoint",
[
"id" => "new-my-content-id",
"title" => "マイコンテンツ",
"contents" => "こんにちは、マイコンテンツ!"
]
);
echo$createResult->id;

下書きコンテンツの作成

$createResult = $client->create(
"endpoint",
[
"title" => "下書きコンテンツ",
"contents" => "こんにちは、下書きコンテンツ!"
],
[ "status" => "draft" ]
);
echo$createResult->id;

コンテンツの更新

$updateResult = $client->update("endpoint", [
"id" => "new-my-content-id",
"title" => "こんにちは、microCMS PHP SDK!"
]);
echo$updateResult->id;

オブジェクト形式のコンテンツの更新

$updateResult = $client->update("endpoint", [
"title" => "こんにちは、microCMS PHP SDK!"
]);
echo$updateResult->id;

コンテンツの削除

$client->delete("endpoint", "new-my-content-id");

Releases

Packages

Used by

Contributors

Languages