简体   繁体   中英

ZF2 restservice GET error

how do i access the rest service http://www.example.com/zf2/services/call/login which is getting an error "error-router-no-match"

My 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`'`,
    ),
),

);

As I see you have invalid route setup. At first: one services section rewrites another. You can just set default values, so first section services is unnecessary. Second section doesn't have appropriate route - it can handle only requests like

To accept services/call/login route have to be something like this

<?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',
        ),
    ),
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM