アドオンを使用して新しいエンティティーを持つAPIを拡張する方法;
- アドオンディレクトリに
Tygh/Api/Entitiesサブディレクトリを作成 Tygh/Api/Entitiesディレクトリに新しいエンティティーを含んだファイルを作成(例、Things.php)- このファイルでは、ネームスペース
Tygh\Api\EntitiesのApi\Entityクラスから受け継がれた同じ名前のクラスを定義可能です。 - このクラスは4つの必須メソッド全てを実装する必要があります(CRUD)。
基本的なAPIテンプレート
<?php
namespace Tygh\Api\Entities;
use Tygh\Api\AEntity;
use Tygh\Api\Response;
class Things extends AEntity
{
public function index($id = '', $params = array())
{
return array(
'status' => Response::STATUS_OK,
'data' => array()
);
}
public function create($params)
{
return array(
'status' => Response::STATUS_CREATED,
'data' => array()
);
}
public function update($id, $params)
{
return array(
'status' => Response::STATUS_OK,
'data' => array()
);
}
public function delete($id)
{
return array(
'status' => Response::STATUS_NO_CONTENT,
);
}
public function privileges()
{
return array(
'create' => 'create_things',
'update' => 'edit_things',
'delete' => 'delete_things',
'index' => 'view_things'
);
}
}