ZF2 restservice GET error


ZF2 restservice GET error

如何访问rest服务http://www.example.com/zf2/services/call/login,该服务获得错误"error-router-no-match"

我Module.config

return array(
'router' => array(
    'routes' => array(
        'services' => array(
            'type' => 'Zend'Mvc'Router'Http'Literal',
            'options' => array(
                'route'    => '/services',
                'defaults' => array(
                    '__NAMESPACE__' => 'Restapi'Controller'restapi',
                ),
            ),
        ),            
        'services' => array(
            'type'    => 'segment',
            'may_terminate' => true,
            'options' => array(
                'route'    => '/services[/:id]',
                'constraints' => array(
                                        'id'=>'[0-9a-zA-Z]+',
                                      ),
                'defaults' => array(
                    'controller' => 'Restapi'Controller'rest',
                ),
            ),
        ),
    ),
),
'controllers' => array(
    'invokables' => array(
        'Restapi'Controller'Rest' => 'Restapi'Controller'RestapiController',            
    ),
),
'view_manager' => array(
    'strategies' => array(
        'ViewJsonStrategy`'`,
    ),
),

);

我看到你有无效的路由设置。起初:一个服务部分重写了另一个。您可以只设置默认值,因此第一部分的服务是不必要的。第二部分没有合适的路由——它只能处理像

这样的请求
  • http://www.example.com/zf2/services
  • http://www.example.com/zf2/services/call

要接受服务/调用/登录路由必须像这样

<?php
return array(
    'router'      => array(
        'routes' => array(
            'services' => array(
                'type'          => 'segment',
                'may_terminate' => true,
                'options'       => array(
                    'route'       => '/services[/[:controller[/:action]]]',
                    'constraints' => array('id' => '[0-9a-zA-Z]+',),
                    'defaults'    => array(
                        'controller' => 'Restapi'Controller'rest',
                        'action'     => 'index', // Default action for "/services" route
                    ),
                ),
            ),
        ),
    ),
    'controllers' => array(
        'invokables' => array(
            'Restapi'Controller'Rest' => 'Restapi'Controller'RestapiController',
        ),
    ),
    'view_manager' => array(
        'strategies' => array(
            'ViewJsonStrategy',
        ),
    ),
);