Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Pagination issue

Code:

$db = \Phalcon\DI::getDefault()->get('db');
$stmt = $db->prepare("SELECT id,first_name,last_name,contact_email from contacts where flag=1 UNION ALL SELECT id,first_name,last_name,bounce_email_address from mailchimp_import_contacts where flag=1");
$stmt->execute();
$contacts = $stmt->fetchAll(\PDO::FETCH_ASSOC);

When I excuted above i am getting issue like: Invalid data for paginator.

$paginator = new Phalcon\Paginator\Adapter\Model(array(
"data" => $contacts,    //Data to paginate
"limit" => 30,           //Rows per page
"page" => $numberPage   //Active page
));

PLs help to fix it...



84.1k
Accepted
answer

You have to pass a valid resultset to the paginator:

use Phalcon\Mvc\Model\Resultset\Simple as Resultset;

$db = \Phalcon\DI::getDefault()->get('db');
$result = $db->query("SELECT id,first_name,last_name,contact_email from contacts where flag=1 UNION ALL SELECT id,first_name,last_name,bounce_email_address from mailchimp_import_contacts where flag=1");

$contacts = new Resultset(null, new Contacts, $result);

$paginator = new Phalcon\Paginator\Adapter\Model(array(
"data" => $contacts,    //Data to paginate
"limit" => 30,           //Rows per page
"page" => $numberPage   //Active page
));