【问题标题】:How to use zend pagination如何使用zend分页
【发布时间】:2014-12-07 00:29:24
【问题描述】:

我想在zend framework1中分页,
在模型中,我声明了 Books.php (application/models/books.php):

<?php
class Model_Books extends Zend_Db_Table_Abstract
{
    protected $_name = 'subscriber';
}

在控制器中,我有这个 BookControllers.php(应用程序/控制器/BooksControllers):

<?php
class BooksController extends Zend_Controller_Action
{
    public function listAction() 
    {
        $booksTBL = new Model_Books();
        $this ->view->books= $booksTBL->fetchAll();
    }
}

在视图中,我使用 Table 来显示数据库查询 (list.phtml)

<?php echo $this->doctype() ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>لیست</title>
  <?php echo $this->headLink()->appendStylesheet('/css/global.css') ?>
</head>
<body>
 <div class="datagrid">
    <table style="border-collapse: collapse; text-align: center; width: 100%;">
      <tr>
        <th>id</th>
        <th>username</th>
        <th>domain</th>
        <th>password</th>
        <th>email address</th>
        <th>ha1</th>
        <th>ha1b</th>
      </tr>

        <?php 
            foreach ($this ->books as $key =>$value)
            {

                echo '<tr><td>'.$value->id.'</td><td>'.$value->username.'</td><td>'.
                $value->domain.'</td><td>'.$value->password.'</td><td>'.$value->email_address
                .'-</td><td>'.$value->ha1.'</td><td>'.$value->ha1b.'</td></tr>';
            }
        ?>
  </table>
 </div>
</body>
</html>

如何对信息进行分页,每页10条记录限制?

【问题讨论】:

    标签: php database zend-framework pagination zend-paginator


    【解决方案1】:

    尝试更改一下控制器的操作代码:

    public function listAction() 
    {
        $request = $this->getRequest();
        $page = $request->getParam('page', 1);
    
        $booksModel = new Model_Books();
        $select = $booksModel->select();
        $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbTableSelect($select));
        $paginator->setCurrentPageNumber($page);
        $paginator->setItemCountPerPage(10);
    
        $this->view->books = $paginator;
    }
    

    然后您可以像以前一样使用您的视图,但是 - 您可能需要在页面之间导航的按钮。 Here's 基本分页器部分,使用它作为 Zend 文档中提到的视图:

    <?php echo $this->paginationControl($this->paginator,
                                        'Sliding',
                                        'my_pagination_control.phtml'); ?>
    

    Zend_Paginator docs - 有很多与本课程相关的问题的答案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-04
      • 1970-01-01
      相关资源
      最近更新 更多