douzhang6496 2015-12-21 20:21
浏览 33

如何从Zend路由告诉API版本

I recently picked up a client's old project. It was originally developed using Zend framework, which is a new one to me. I'm trying to modify the correct file but they have three versions of the API.

in the module.config they have the route as:

'api.rest.social-credential' => array(
                'type' => 'Segment',
                'options' => array(
                    'route' => '/social-credential[/:social_credential_id]',
                    'scheme' => 'http',
                    'defaults' => array(
                        'controller' => 'Api\\V1\\Rest\\SocialCredential\\Controller',
                    ),
                ),
            ),

To me this means the controller I should be looking at is v1 or Api\\V1\\Rest\\SocialCredential\\Controller However, when looking through the code and seeing how the server responds it is clearly running v3.

The two Controllers are defined as follows: v1

'Api\\V1\\Rest\\SocialCredential\\Controller' => array(
            'listener' => 'Api\\V1\\Rest\\SocialCredential\\SocialCredentialResource',
            'route_name' => 'api.rest.social-credential',
            'route_identifier_name' => 'social_credential_id',
            'collection_name' => 'social_credential',
            'entity_http_methods' => array(
                0 => 'PATCH',
            ),
            'collection_http_methods' => array(),
            'collection_query_whitelist' => array(),
            'page_size' => '25',
            'page_size_param' => '',
            'entity_class' => 'Api\\V1\\Rest\\SocialCredential\\SocialCredentialEntity',
            'collection_class' => 'Api\\V1\\Rest\\SocialCredential\\SocialCredentialCollection',
            'service_name' => 'SocialCredential',
        ),

v3

'Api\\V3\\Rest\\SocialCredential\\Controller' => array(
            'listener' => 'Api\\V3\\Rest\\SocialCredential\\SocialCredentialResource',
            'route_name' => 'api.rest.social-credential',
            'route_identifier_name' => 'social_credential_id',
            'collection_name' => 'social_credential',
            'entity_http_methods' => array(
                0 => 'PATCH',
                1 => 'DELETE',
            ),
            'collection_http_methods' => array(),
            'collection_query_whitelist' => array(),
            'page_size' => '25',
            'page_size_param' => '',
            'entity_class' => 'Api\\V3\\Rest\\SocialCredential\\SocialCredentialEntity',
            'collection_class' => 'Api\\V3\\Rest\\SocialCredential\\SocialCredentialCollection',
            'service_name' => 'SocialCredential',
        ),

I find nothing in the module.config that makes me believe that v3 should be the target other then this definition existing. Either I'm missing something or I don't understand how Zend routing works. Could someone shed some light on this please?

  • 写回答

1条回答 默认 最新

  • doucong1268 2015-12-21 21:02
    关注

    Finally found it, the default_version under zf-versioning

    'zf-versioning' => array(
            'uri' => array(
                ...
                13 => 'api.rest.social-credential',
            ),
            'default_version' => 3,
        ),
    

    More info here: https://github.com/zfcampus/zf-versioning

    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改