phalcon mongodb ODM 分页

<?php
public function indexAction()
    {
        $currentPage = $this->request->getQuery('page', 'int');
        $users = Users::find();

        $paginator = new \Phalcon\Paginator\Adapter\NativeArray(
            array(
                "data" => $users,
                "limit"=> 1,
                "page" => $currentPage
            )
        );

        $page = $paginator->getPaginate();
        $this->view->setVar("page", $page);
    }
?>
<html>
<table>
    <tr>
        <th>Id</th>
        <th>Name</th>
        <th>Type</th>
    </tr>
    <?php foreach ($page->items as $item) { ?>
        <tr>
            <td><?php echo $item->_id; ?></td>
            <td><?php echo $item->name; ?></td>
        </tr>
    <?php } ?>
</table>

<a href="/index/index">First</a>
<a href="/index/index?page=<?= $page->before; ?>">Previous</a>
<a href="/index/index?page=<?= $page->next; ?>">Next</a>
<a href="/index/index?page=<?= $page->last; ?>">Last</a>

<?php echo "You are in page ", $page->current, " of ", $page->total_pages; ?>
</html>

转载请注明来源:新一 » phalcon mongodb ODM 分页

赞 (1) 评论 (0) 分享 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址