How do I access query parameter values in Laminas API Tools

I want to access multiple query parameters in the URL, please refer to the screenshot.
In the corresponding resource file it gets mapped on the fetch($id) method. I can see only one parameter as expected, how do I access the other parameters as given in the screenshot GET method. If someone wants to know why do I need multiple parameters ? The answer is - these multiple parameters collectively identifies an item in the db table.

So my question is how do I specify multiple parameters and access the same in the corresponding resource file.

Good morning,

hope you 're doing well. It’s nice to see that you’re making progress with the API tools. Since resources are event driven and follow a specific pattern, it 's not a good practice to handle more than one identifier in a fetch method, which is designed to return a specific dataset. From the point of view of the consideration, in your case you rather execute a fetchAll with filter parameters.

There is a good repository to archive what you want, when you 're using doctrine orm: GitHub - laminas-api-tools/api-tools-doctrine-querybuilder: Laminas API Tools Doctrine QueryBuilder module

You can set filter parameters with the doctrine query builder, that do exactly what you want. So you don’t have to reprogram this filter for each resource. It works directly for all resources because of the event driven system of the query builder.

Nevertheless you can archive this functionality on your own. Let us have a look at the \Laminas\ApiTools\Rest\AbstractResourceListener.php file in line 182 and following.

...
case 'fetchAll':
    $queryParams = $event->getQueryParams() ?: [];
    return $this->fetchAll($queryParams);
...

As you can see the fetchAll method retrieves all query params so that you can use it in your implementation. This leads us to your query. Assuming it is formed like

test.apitools.eu/v1/categories-description?id[]=22&id[]=33

In the given query we got two ids 22 and 33. In your resource you can access them as in the following example.

public function fetchAll($params = [])
{
    $ids = $params['id']; // array with the given id 's in the query
    ...
}

Of course, you can also use the query parameters in all other methods of your resource.

public function fetch($id)
{
    $queryParams = $this->event->getQueryParams() ?: [];
    
    $ids = [];
    if (isset($queryParams['id'])) {
        $ids = $queryParams['id']; // array with the given ids from the query
    } 
}

Thanks! Hope you are doing good too. That was helpful.