Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Can';不要称一个特定的实体为Apigility_Php_Zend Framework_Laminas Api Tools - Fatal编程技术网

Php Can';不要称一个特定的实体为Apigility

Php Can';不要称一个特定的实体为Apigility,php,zend-framework,laminas-api-tools,Php,Zend Framework,Laminas Api Tools,我不能通过GET调用我的Apigility端点。我有以下配置: 'router' => [ 'routes' => [ ... 'test' => [ 'type' => Segment::class, 'options' => [ 'route' => '/test[/:id]', 'defaults' =&

我不能通过GET调用我的Apigility端点。我有以下配置:

'router' => [
    'routes' => [
        ...
        'test' => [
            'type' => Segment::class,
            'options' => [
                'route' => '/test[/:id]',
                'defaults' => [
                    'controller' => Resource\TestResource::class,
                ],
            ],
            'may_terminate' => true,
        ],
        ...
    ],
],
'zf-rest' => [
    Resource\TestResource::class => [
        'listener' => Resource\TestResource::class,
        'route_name' => 'api/rest/test',
        'route_identifier_name' => 'id',
        'entity_http_methods' => [
            'GET',
        ],
        'collection_http_methods' => [
        ],
    ],
],
我的资源如下所示:

class TestResource extends AbstractResourceListener
{
    public function fetch($id)
    {
        return ...
    }
}

现在,我尝试在浏览器中打开url/api/rest/test,并获得一个405(不允许使用方法)。

配置的整个过程是:

'routes' => [
    'api' => [
        'type' => Literal::class,
        'options' => [
            'route' => '/api',
        ],
        'may_terminate' => false,
        'child_routes' => [
            'rest' => [
                'type' => Literal::class,
                'options' => [
                    'route' => '/rest',
                ],
                'may_terminate' => false,
                'child_routes' => [
                    'test' => [
                    ...
这就是为什么我的路线名称是:

'route_name' => 'api/rest/test',
这不是问题所在。但应用程序似乎希望调度fetchAll方法(作为集合),而不是fetch方法(作为实体),我不知道为什么

现在,我尝试在浏览器中打开url/api/rest/test,得到一个405(不允许使用方法)

您的URL实际上正在调用一个集合。要调用实体,需要指定实体id,即:/api/rest/test/1
只要URL末尾没有ID,Apigility就会匹配收集路径,并且根据您的配置,绝对不允许使用http方法进行收集。

您是否从Apigility的(管理员/用户面板)配置了GET方法