I follow this tutorial http://techportal.inviqa.com/2013/12/03/create-a-restful-api-with-apigility/ and create a db-connected API from code-connected.
And have for Entity the above methods that get me the possibility to choice what field are returned in JSON
public function getArrayCopy()
{
return array(
'id' => $this->id,
'cat_id' => $this->cat_id,
'name' => $this->name,
'url' => $this->url,
);
}
public function exchangeArray(array $array)
{
$this->id = $array['id'];
$this->cat_id = $array['cat_id'];
$this->name = $array['name'];
$this->url = $array['url'];
}
Now i wont do the same thing for Collections (return only some fields of all table field in db)... but can't understood where.
I have the Resource that call Mapper
return $this->mapper->fetchAll();
and in mapper
public function fetchAll()
{
$select = new Select('eye_medic');
$paginatorAdapter = new DbSelect($select, $this->adapter);
$collection = new MedicCollection($paginatorAdapter);
return $collection;
}
how i can edit this for create my own collection arrays and get only chosed by me fields?
In example Response for entity (very good):
[id] => 3
[cat_id] => 1
[name] => Abbadini Dr. Pasqualino Odontoiatra
[url] => abbadini-dr-pasqualino-odontoiatra
[_links] => stdClass Object ...
Response for collection are with full database field (not good, i want only 4 fields)
[15] => stdClass Object
(
[id] => 19
[user_id] => 0
[country_id] => 105
[region_id] => 13
[province_id] => 68
[city_id] => 5889
[url] => amicarelli-dr-alfonso-studio-dentistico
[name] => Amicarelli Dr. Alfonso Studio Dentistico
[description] =>
[poster] =>
[cat_id] => 1
[status] => LIVE
[publish_ts] => 2014-11-13 18:46:47
[edited_ts] =>
[_links] => stdClass Object ...
Thanks in advance