Pagination in Zend

后端 未结 2 840
一整个雨季
一整个雨季 2021-01-03 02:35

Friends,

I want to create pagination in Zend Framework. I\'m new to ZF.

index.phtml is given below

N
2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-03 03:14

    I try to help you based on what I have in my ZF project.

    So, in your class Model_DbTable_Order you can defined a method called e.g. getOnePageOfOrderEntries() as follows:

     /**
     * Return one page of order entries
     *
     * @param int $page page number
     * @return Zend_Paginator Zend_Paginator
     */
    public function getOnePageOfOrderEntries($page=1) {
    
        $query = $this->select();
        $paginator = new Zend_Paginator(
                new Zend_Paginator_Adapter_DbTableSelect($query)
        );
        $paginator->setItemCountPerPage(100);
        $paginator->setCurrentPageNumber($page);
        return $paginator;
    }
    

    Than in indexAction you can have something like this:

     public function indexAction()
    {
        $this->view->title = "My Orders";
        $this->view->headTitle($this->view->title, 'PREPEND');
        $orders = new Model_DbTable_Orders();
        //$this->view->orders = $orders->fetchAll();
    
        $page = $this->_request->getParam('page');
        if (empty($page)) { $page = 1; }
    
        $paginator = $orders->getOnePageOfOrderEntries($page);
        $this->view->paginator = $paginator;
    
    }
    

    In your index.phtml view you could have something similar to this:

      paginator)): ?>
        paginator as $order): ?>
    
        
    Name Quantity  
    name;?> quantity;?>
    paginationControl($this->paginator, 'Sliding','partial/my_pagination_control.phtml'); ?>

    Where my_pagination_control.phtml is as follows (this is just copy-paste what I have and it is from the ZF Reference quide):

       pageCount): ?>
        
    previous)): ?> Previous | Previous | pagesInRange as $page): ?> current): ?> | | next)): ?> Next Next

    Hope it will be useful.

提交回复
热议问题