【问题标题】:multiple zend pagination controls via ajax and jquery通过 ajax 和 jquery 实现多个 zend 分页控件
【发布时间】:2012-06-15 13:58:58
【问题描述】:

谁能帮我在一个视图中使用 ajax 实现多个 zend 分页。我已经设法实现单分页没问题,但现在我想执行超过1。

这是我的设置:-

添加到引导程序:-

public function _initPaginator(){
    Zend_Paginator::setDefaultScrollingStyle('Sliding');
    Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_control.phtml');   
}

'pagination_control.phtml' 取自 zend 框架手册。

添加到控制器:-

public function init()
{
    parent::init();

    $ajaxContext = $this->_helper->getHelper('AjaxContext');
    $ajaxContext->addActionContext('view', 'html')
                ->initContext();
}

将此添加到控制器操作中:-

public function viewAction()
{

    $query = $this->_em->createQueryBuilder()
       ->select('t')
       ->from('Ajfit\Entity\Ticket', 't')
       ->where('t.engineerFk = :engineer')
       ->orderBy('t.dt', 'desc')
       ->setParameter('engineer', $engineer)
       ->getQuery();

    $paginator =  new Paginator($query);
    $adapter->getIterator();

    $zend_paginator = new \Zend_Paginator($adapter);
    $zend_paginator->setItemCountPerPage(3)
                   ->setCurrentPageNumber($this->_getParam('page'));

    $this->view->ticketPaginator = $zend_paginator;
}

将此添加到视图中:-

<div>
    <div id="ticket-history">
       <?php 
             echo $this->render('profile/view.ajax.phtml'); 
         ?>
       </div> 
</div>

<script>
    $(document).ready(function() {
        $('.pagination-control').find('a').live('click', function(e) { 
            var link = $(this); 
            $('#ticket-history').load(link.attr('href'), { format: 'html' }); 
            return false;
        });
    });
</script>

我的“profile/view.ajax.phtml”脚本包含:-

<?php

     echo '<table border="0" width="100%" cellspacing="3" cellpadding="3"><tr>';

     foreach($this->ticketPaginator as $ticket){
         echo '<td>' . $ticket->getSubject() . '</td>';
     }

     echo '</tr></table>';
 ?>

<?php 
    echo $this->paginationControl($this->ticketPaginator);
?>

这一切都很好,但是,如何为不同的学说实体在此视图中添加第二个或第三个分页器?

任何帮助将不胜感激。

谢谢

安德鲁

【问题讨论】:

    标签: php jquery zend-framework pagination doctrine-orm


    【解决方案1】:

    为此,您必须在init() 中使用多个addActionContext

        $this->_helper->ajaxContext->addActionContext('view', 'html')->initContext();
        $this->_helper->ajaxContext->addActionContext('list', 'html')->initContext();
    

    你可以继续

    在控制器中添加操作为listAction() 用于分页器创建文件为list.ajax.phtml 并在其中添加所需的代码

    【讨论】:

    • 嗯,没错,但那有什么作用呢?另外,如果我在viewAction 函数中创建第二个分页器,请说:-$this-&gt;view-&gt;replyPaginator = $zend_reply_paginator; 在视图中我如何访问引用echo $this-&gt;render('profile/view.ajax.phtml'); ,因为此文件包含ticketPaginator 的代码,而不是新的@987654330 @?
    • 你能给我一个例子吗,因为我是 ajax 和 zend 的新手
    • 我有点理解你的意思,但我认为有一个问题,分页链接显示为/profile/view/name/&lt;name&gt;/page/&lt;x&gt;,并且它一直在调用 viewAction,它根本没有调用list 操作,我错过了什么吗?
    【解决方案2】:

    如果您操纵分页链接使其调用其他操作,则可以解决此问题。

    例如:在View Part中,你可以使用paginationControl方法的第四个参数来定义指向另一个动作的链接。然后应在pagination_control.phtml 中调用此链接。

    【讨论】:

    • 您能否通过提供一些其他详细信息或代码示例来扩展此答案?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-26
    • 2015-07-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多