0
votes

I am using onapp api with one of my websites. Now I need to display a list of servers that the user have purchased. I got these data as an object as response from API call to onapp server. But sometimes, it is a huge list and so I need to paginate it. My current pagination is database oriented and it is selecting the particular number of data and limit is given according to the page. But in api response. I got all the responses at a time.

So how can I paginate in server side rather than depending on client side pagination.. ?

1

1 Answers

0
votes

I had to do the same thing when calling a Web Service from SF1.4, but in my case the WS admits pagination parameter. Anyway I wanted to use sfPager with the results, so I created a class inheriting from sfPager:

class sfWSPager extends sfPager {
public function getResults() {
    return $this->results;
}

public function init() {
    if (0 == $this->getPage() || 0 == $this->getMaxPerPage() || 0 == $this->getNbResults())
        $this->setLastPage(0);
    else {
            $this->setLastPage(ceil($this->getNbResults() / $this->getMaxPerPage()));
        }
}

public function setResults($results) {
    $this->results = $results;
}

public function setNbResults($nb) {
    parent::setNbResults($nb);
}
}

Then in my action:

$this->pager = new sfWSPager(null);
$this->pager->setResults($dataResultsFromWS);
$this->pager->setNbResults($totalNbOfResults);
$this->pager->setPage($page);

$this->pager->init();

So I keep using Symfonys sfPager capabilities.