Collection_query_whitelist does not filter

Hi!

I am trying to filter by URL params without effects and I could not find a reason of why.

I use “main_affiliate_dni” as param and I would like to filter by this column with same name.

If I override fetchAll function I see $data contains this param but I could not debug more and there are not many examples on the forums.

Thank you

Do i need to append “main_affiliate_dni” into the route matches?

Hi, @juliangorge can you share your PHP version and Api Tool version? Thanks!

Hello @Altamash80 nice to see you again.
API Tool 1.6.0, PHP 7.4.

You could do it by overwriting fetchAll with another implementation, but I think the official documentation says that it would be easier to

Hi, yes the official documentation is in my opinion very old and I don’t think it got updated but rather just carried over. Because on the home page of the documentation the video there still has the Zend Framework logo. In my opinion, Apgility was left hanging after the introduction of Mezzio. If overriding fetchAll works then use it otherwise if you’ve found something which would help others you can share it here. Thanks!

Hi dude,
I had to overwrite fetchAll to use query whitelist, here an example:


<?php
namespace API\V1\Rest\Relatives;

use Laminas\ApiTools\DbConnectedResource;

class RelativesResource extends DbConnectedResource
{
    public function fetchAll($data = [])
    {
        return new RelativesCollection($this->table->getRelatives($data));
    }
}
<?php
namespace API\V1\Rest\Relatives;

use Laminas\Db\TableGateway\TableGateway;
use Laminas\Paginator\Adapter\DbSelect;

class RelativesTableGateway extends TableGateway
{
    // $data contains your query whitelist
    public function getRelatives($data = [])
    {
        $select = $this->getSql()->select();
        if(sizeof($data)) $select->where($data->toArray());

        return new DbSelect($select, $this->getAdapter(), $this->getResultSetPrototype());
    }
}

I could not find other solution. Thank you!