2

我遵循本教程http://techportal.inviqa.com/2013/12/03/create-a-restful-api-with-apigility/并从代码连接创建一个 db-connected API。

并为实体提供上述方法,让我可以选择在 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'];
}

现在我不会为 Collections 做同样的事情(只返回 db 中所有表字段的一些字段)......但不明白在哪里。

我有调用 Mapper 的资源

return $this->mapper->fetchAll();

在映射器中

public function fetchAll()
{
    $select = new Select('eye_medic');
    $paginatorAdapter = new DbSelect($select, $this->adapter);
    $collection = new MedicCollection($paginatorAdapter);
    return $collection;
}

我如何编辑它以创建我自己的集合数组并仅由我选择字段?

在实体的示例响应中(非常好):

[id] => 3
[cat_id] => 1
[name] => Abbadini Dr. Pasqualino Odontoiatra 
[url] => abbadini-dr-pasqualino-odontoiatra
[_links] => stdClass Object ...

收集的响应是完整的数据库字段(不好,我只想要 4 个字段)

[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 ...

提前致谢

4

0 回答 0