MODX Community

pdoFetch is giving error on a snippetcall

Hoi all,

I have a problem/error in the logs, when trying to setup and building a filter sytem at the front-end.

this is the snippet, which i use in pdoPage (pdoResources), to get the &tvFilters.

<?php
$modx->setPlaceholder('archfilter', $_POST['optiearch']);
$modx->setPlaceholder('typewoningfilter', $_POST['optiewoning']);
$modx->setPlaceholder('plaatsfilter', $_POST['optieplaats']);
$modx->setPlaceholder('aannemerfilter', $_POST['optieaann']);
$modx->setPlaceholder('kamersfilter', $_POST['optiekame']);

$archfilter = $modx->getPlaceholder('archfilter');
$typewoningfilter = $modx->getPlaceholder('typewoningfilter');
$plaatsfilter = $modx->getPlaceholder('plaatsfilter');
$aannemerfilter = $modx->getPlaceholder('aannemerfilter');
$kamersfilter = $modx->getPlaceholder('kamersfilter');

    if(empty($archfilter)) {
        $archfilter == "";
    }
    else {
        $archfilter = "architect==" . $archfilter;  
    }
    
    if(empty($typewoningfilter)) {
        $typewoningfilter == "";
    }
    else {
        $typewoningfilter = "type-woning==" . $typewoningfilter;  
    }
    
    if(empty($plaatsfilter)) {
        $plaatsfilter == "";
    }
    else {
        $plaatsfilter = "plaats==" . $plaatsfilter;  
    }
    
    if(empty($aannemerfilter)) {
        $aannemerfilter == "";
    }
    else {
        $aannemerfilter = "aannemer==" . $aannemerfilter;  
    }
    
    if(empty($kamersfilter)) {
        $kamersfilter == "";
    }
    else {
        $kamersfilter = "kamers==" . $kamersfilter;  
    }
    
$myfilter = array ("$archfilter","$typewoningfilter","$plaatsfilter","$aannemerfilter","$kamersfilter");
$comma_separated = implode(",", array_filter($myfilter));

echo $comma_separated;

and then error :

[2020-03-25 10:48:19] (ERROR @ /home//core/components/pdotools/model/pdotools/pdofetch.class.php : 949) Recoverable error: Argument 1 passed to pdoFetch::replaceTVCondition() must be of the type array, null given, called in /home//core/components/pdotools/model/pdotools/pdofetch.class.php on line 468 and defined
[2020-03-25 10:48:19] (ERROR @ /home/******/core/components/pdotools/model/pdotools/pdofetch.class.php : 959) PHP warning: Invalid argument supplied for foreach()

could someone explain these errors

greetings Appeltje

All,

Found the solution, by filtering out NULL outcome in array_filter , by adding ‘strlen’

And it works

Greetings, Appeltje