0

这可能看起来更简单,但我很难过。我有一个简单的控制器,它构建了一个用于输入参数的小表单。提交表单时,将重绘同一页面,顶部是相同的表单,但其下方是结果的分页视图。我的控制器在这里:

public function indexAction()
{
    $form = new Application_Form_Battery();

    $request = $this->getRequest();
    if ($request->isPost()) {
        $data = $request->getPost();
        $form->populate($data);

        // get the data
        Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml');
        $reportsTBL = new Model_DBTable_Reports();
        $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Array($reportsTBL->getBatteryLog($data)));
        $paginator->setCurrentPageNumber($this->_getParam('page',1))
              ->setItemCountPerPage(50);
        $this->view->paginator = $paginator;
    }   
    $this->view->form = $form;
}

可以看到,表单提交后,分页结果被view->form语句覆盖了……表单提交后如何合并呢?我不能有两个视图调用...

4

2 回答 2

1

像这里未经测试的东西,

索引控制器

    public function indexAction()
    {
                .....
            $_category = new Admin_Model_DbTable_Category();
            $category = $_category->browse($browseArray);
            $this->view->vCount = count($category);
        $paginator = Zend_Paginator::factory($category);
        $page = ($postData['page'] > 0) ? $postData['page'] : 1;
        $paginator->setCurrentPageNumber($page); 
        $paginator->setItemCountPerPage(10);
        $paginator->setPageRange(5);
        $this->view->categoryList   = $paginator;  // print_obj($paginator);
....
}

索引.phtml

.....
<ul>
     <?php if (count($this->categoryList) != 0) { ?>
       <?php
         foreach ($this->categoryList AS $key => $category) {
           ?>
             <li>

               <div >
                   <?php echo $category['name'] ?>

               </div>
              </li>
         <?php } ?>
         <li>
            <div><?php echo "Total Category(" . $this->vCount . ")"; ?></div>
                                <div style="text-align:center;"><?php echo $this->paginationControl($this->categoryList, 'Sliding', 'pagination.phtml'); ?></div>
                            </li>
                            <?php } else { ?>
                            <li><div style="text-align:center;">No records found</div></li> 
                    <?php } ?>
                    </ul>
...

分类.php

class Admin_Model_DbTable_Category extends Zend_Db_Table_Abstract
{
...
    protected $_name = 'category';
    protected $_primary = 'category_id';


    public function browse($browseArray = array()) 
    {
        extract($browseArray);

        $whereSQL       = ' `parent` = 0 ';

        if($category_id)                
            $whereSQL   .= ' AND `category_id` = "'. $category_id .'"';
        if($catname)
            $whereSQL   .= ' AND `name` = "'. $catname .'"';
        if($name)
            $whereSQL   .= ' AND `name` LIKE "%'. $name .'%"';  
        if($description)
            $whereSQL   .= ' AND `description` LIKE "%'. $description .'%"';    
        if($status) 
            $whereSQL   .= ' AND `status` = "'. $status .'"';   

        $select         = $this->_db->select()
                            ->from($this->_name)
                            ->where($whereSQL);
        $result         = $this->getAdapter()->fetchAll($select);

        return $result;
    }
    ....
}

您可以使用名为 browse 的通用函数从 table 获取结果,通过使用结果我们可以在页面呈现时对数据进行分页。

于 2012-10-02T05:51:27.100 回答
0

I solved it. I was using a view that called a form template and I was trying to display the paginated results on that form. I moved the paginated results to the actual view script and everything is solved.

Thanks for the help.

于 2012-10-02T15:28:53.960 回答