duanqiao2006 2015-03-12 09:34
浏览 80

Apigility中忽略了水分器设置

In Apigility it's possible to set a Hydrator for every Entity -- either over the Apigility UI

enter image description here

or directly in the module.config.php, e.g.:

return array(
    ...
    'zf-hal' => array(
        'metadata_map' => array(
            'Portfolio\\V2\\Rest\\Project\\ProjectEntity' => array(
                'entity_identifier_name' => 'id',
                'route_name' => 'portfolio.rest.project',
                'route_identifier_name' => 'id',
                'hydrator' => 'Zend\\Stdlib\\Hydrator\\ObjectProperty',
                // 'hydrator' => 'MyNamespace\\Hydrator\\ProjectHydrator',
            ),
            ...
        ),
        ...
    ),
    ...
);

See also the documentation.

Currently I'm using the ClassMethods hydrator for all my entities.

Now I tried to change the setting to a custom hydrator. I've also tried another Zend hydrator. But whatever I do, only the hydrated I have defined in the `module.config.php is ignored.

EDIT: It works for sigle entities, but not for collections. I've checked this with the debugger and see: when I retieve a collection, my custom hydrator doesn't get called. I cannot find out, which hydrator is actually being used -- I set breakpoints and even wrote die()s in the extract() and hydrate() methods of all hydrators (ArraySerializable, ClassMethods, ObjectProperty, Reflection, and also in my custom ProjectHydrator), but the application didn't notice that at all and is still working. Seems so, that no hydration is made at all...

What is wrong here and how to get hydration settings working correctly?

  • 写回答

2条回答 默认 最新

  • dongnuo4594 2015-04-28 20:46
    关注

    When you defined the Entity class for your service, you also have the option to configure the Collection entity for your service. You need to to associate your hydrator to the Collection entity in your metadata.

    return [
        'zf-rest' => [
            'Portfolio\\V2\\Rest\\Project\\Controller' => [
                // other config
                'entity_class' => 'Portfolio\\V2\\Rest\\Project\\ProjectEntity',
                'collection_class' => 'Portfolio\\V2\\Rest\\Project\\ProjectCollection',
            ]
        ],
        'zf-hal' => [
            'metadata_map' => [
                'Portfolio\\V2\\Rest\\Project\\ProjectEntity' => [
                    // other config
                    'hydrator' => 'MyNamespace\\Hydrator\\ProjectHydrator'
                ],
                'Portfolio\\V2\\Rest\\Project\\ProjectCollection' => [
                    // other config
                    'hydrator' => 'MyNamespace\\Hydrator\\ProjectCollectionHydrator'
                ]
            ]
        ]
    ]
    
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀