We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Problem with Criteria::fromInput - BUG ?

I use the following code:

$query = Criteria::fromInput($this->di, 'Objects', $array);
$this->persistent->searchParams = $query->getParams();

if ($this->persistent->searchParams) {
    $parameters = $this->persistent->searchParams;
}

$objects = Objects::find($parameters);

The problem is, when I have only one value in $array (Array ( [country_id] => HR )) , I get ''Undefined variable ""parameters"" error.

When I have multiple values, it works fine.

Is this a bug or is it supposed to work like this?



98.9k

To avoid that error you can change it to:

$query = Criteria::fromInput($this->di, 'Objects', $array);

$objects = Objects::find($query->getParams());


17.0k

This is not solving the problem.

If $array has only one parameter, $query->getParams() returns nothing.

If it has more that one, it's ok..

It does seem to me like a bug, this is my full searchAction code: https://pastebin.com/4psXDHSr



17.0k
Accepted
answer

Ok, i found my error... I should have used cc_fips instead of country_id