Forum
Adding filters with GET variables
Hi all ,
Im trying to perform a search by using the filter options with collections. I'm facing a bit of trouble with actually making the filter part dynamic . have a look at what im trying to achieve .
$collection = perch_collection('property', [
'template'=>'search_result.html',
'filter' => [
foreach($_GET as $key => $value){
[
'filter' => $key,
'match' => 'eq',
'value' => $value,
],
}
]
]
,true);
How do i make the filters add to the array ? Plus i have also tried one more thing .
Passing a range to the filter variable . My output from GET is "0-300000000"
$exploded=explode("-",$pricerangetemp);
$value = print_r ("'".$exploded[0] . "," . $exploded[1] . "'");
[
'filter' => 'price',
'match' => 'eqbetween',
'value' =>$value,
],
This doesnt seem to work .
This is just a PHP syntax point, really. To translate what you're doing directly, I would do this:
But you should be careful doing that, as it would break if anything unexpected was on the query string. That happens more often than you might think.
So instead, check against known good values (
$permitted_keys
below):Hi Drew ,
Thanks a lot for your reply !
Btw , how do i work the second part out .
Passing a range to the filter variable . My output from GET is "0-300000000"
This doesnt seem to work .
Got this resolved .
Hi Drew ,
i just displayed the filters array . Do let me know what is wrong here .
I am using the same for loop with a basic add on .
What problem are you seeing?