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

Search function

https://pastebin.com/dCw1HYB7

The link above is my code for GET search function . The search is performed well for the first time, but when I clicked on the ''next page'' button, the results are wrong and different than what was on the first page.

Can somebody please point me what am I doing wrong?

Thanks



33.8k

So the problem is that in the second page you are getting different items than in the first one? That's how you use pagination (because you are doing that, isn't it?)



17.0k

Exactly. The items on second page are different



33.8k

Also it's value? From the Phalcon documentation (https://docs.phalcon.io/es/latest/reference/pagination.html#data-pagination):

The process of pagination takes place when we need to present big groups of arbitrary data gradually. Phalcon\Paginator offers a fast and convenient way to split these sets of data browsable pages.

I don't see what's the problem. You take a range of results to present on the view, nothing more.



17.0k
Accepted
answer
edited Sep '14

Solved the following way:

//  objects/index action     
$this->persistent->objects = NULL;

//  objects/search action     
if (!$this->persistent->objects) {
    $query = Criteria::fromInput($this->di, 'Objects', $array);
    $parameters = $query->getParams();

    $objects = Objects::find($parameters);
    $this->persistent->objects = $objects;
}

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