2012-02-01 59 views
2

這是我的行動,目前我的網頁正在刷新,我想它ajax.so,沒有刷新整個頁面分頁我是DIV加載refeshing從數據庫的內容。如何Zend_Paginator的轉換爲阿賈克斯在Zend框架

public function calllogsAction(){ 
     if(!Zend_Auth::getInstance()->hasIdentity()){ 
       $this->_redirect('login/login'); 
     } 
     else{ 

     $request = $this->getRequest(); 
     $phone_service_id = $request->getParam("id"); 
     $registry = Zend_Registry::getInstance(); 
     $DB = $registry['DB']; 
     $sql ="SELECT caller_name,call_number,call_start_time,call_duration,call_direction FROM CALL_LOG WHERE phone_service_id = $phone_service_id"; 
     $result = $DB->fetchAll($sql); 
     $page=$this->_getParam('page',1); 
     $paginator = Zend_Paginator::factory($result); 
     $paginator->setItemCountPerPage(10); 
     $paginator->setCurrentPageNumber($page); 
     $this->view->paginator=$paginator; 
     $page = $paginator->getCurrentPageNumber(); 
     $perPage = $paginator->getItemCountPerPage(); 
     $total = $paginator->getTotalItemCount(); 
     $A = ($page - 1) * $perPage + 1; 
     $B = min($A + $perPage - 1, $total); 
     $C = $total; 
     $this->view->assign('url', $request->getBaseURL()); 
     $this->view->assign('total',$total); 
     $this->view->assign('page',$page); 
     $this->view->assign('A',$A); 
     $this->view->assign('B',$B); 
     $this->view->assign('C',$C); 


     } 
    } 

,這是我view.i有更多的在我的觀點,但分頁這裏SI我想刷新該div

<div class="container" id="actualbody" style="margin-left:168px;"> 
<?php 
$sr_no = 1; 

foreach($this->paginator as $record){ 
if($sr_no % 2 == 0){ 
$style = 'class="even-row"'; 
} 
else{ 
$style = 'class="odd-row"'; 
<tr <?php echo $style;?>> 
    <td class="sorting_1"> <input type="checkbox" /> </td> 
    <td ><?php if($record->call_direction =="Outgoing"){?> <img src=" <?php echo $this->baseUrl('/assets/images/outgoing.png'); ?> " /> <?php } elseif($record->call_direction =="Missed") {?> <img src=" <?php echo $this->baseUrl('/assets/images/misses.png'); ?> " /> <?php } else { ?> <img src=" <?php echo $this->baseUrl('/assets/images/incoming.png'); ?> " /> <?php }?></td> 
    <td><?php echo $record->caller_name;?></td> 
    <td><?php echo $record->call_number;?></td> 
    <td ><?php echo $record->call_start_time;?></td> 
    <td ><?php echo $record->call_duration;?></td> 
     </tr> 
     <?php $sr_no ++; }?> 

<div> Showing <?= $this->A; ?> to <?= $this->B; ?> of <?=$this->C; ?> entries </div> 
<div> <?php echo $this->paginationControl($this->paginator, 'Sliding', 'pagination.phtml'); ?></div> 
</div> 

我怎樣才能讓我的分頁通過Ajax

這pagination.phtml

<div class="pagination" style="width:100%"> 
<div style="float:left;width:28%"> 
</div> 
<div style="float:right;width:70%;"> 
    <!-- First page link --> 
    <?php if (isset($this->previous)): ?> 
      <a href="<?= $this->url(array('page' => $this->first)); ?>"> <span class="first ui-corner-tl ui-corner-bl fg-button ui-button ui-state-default ui-state-disabled">Start</span></a> 
    <?php else: ?> 
      <span class="next fg-button ui-button ui-state-default ui-state-disabled">Start</span> 
    <?php endif; ?> 



    <!-- Previous page link --> 

    <?php if (isset($this->previous)): ?> 
      <a href="<?= $this->url(array('page' => $this->previous)); ?>"><span class="previous fg-button ui-button ui-state-default ui-state-disabled">Previous</span></a> 
    <?php else: ?> 
     <span class="next fg-button ui-button ui-state-default ui-state-disabled">Previous</span> 
    <?php endif; ?> 
    <!-- Numbered page links --> 
    <?php foreach ($this->pagesInRange as $page): ?> 
     <?php if ($page != $this->current): ?> 
      <a href="<?= $this->url(array('page' => $page)); ?>"><span class="fg-button ui-button ui-state-default"><?= $page; ?></a></span> 
     <?php else: ?> 
      <span class="fg-button ui-button ui-state-default ui-state-disabled" ><?= $page; ?></span> 
     <?php endif; ?> 
    <?php endforeach; ?> 
    <!-- Next page link --> 
    <?php if (isset($this->next)): ?> 
      <a href="<?= $this->url(array('page' => $this->next)); ?>"><span class="next fg-button ui-button ui-state-default">Next</span></a> 
    <?php else: ?> 
    <span class="next fg-button ui-button ui-state-default ui-state-disabled">Next</span> 
    <?php endif; ?> 
    <!-- Last page link --> 
    <?php if (isset($this->next)): ?> 
      <a href="<?= $this->url(array('page' => $this->last)); ?>"><span class="last ui-corner-tr ui-corner-br fg-button ui-button ui-state-default">End</span></a> 
    <?php else: ?> 
     <span class="next fg-button ui-button ui-state-default ui-state-disabled">End</span> 
    <?php endif; ?> 

</div> 

編輯 我這個代碼

jQuery(function($){ 
var container = $('#paged-data-container'); 

var overlay = $('<div>').addClass('loading overlay'); 

$('.pagination-control').find('a').live('click', function(){ 
    var href = this.href; 
    var pos = this.rel == 'next' ? '-120%' : '120%'; 
    if (Modernizr.history) { 
     history.pushState(location.pathname, '', href); 
    } 
    container.find('.data').animate({ 
     left: pos 
    }, 'slow', function(){ 
     var dataContainer = container.find('.paged-data').addClass('loading'); 
     $.get(href, { format: 'html' }, function(data){ 
      dataContainer.removeClass('loading'); 
      container.html(data); 
     }, 'html'); 
    }); 
    return false; 
}); 

var initialPath = location.pathname; 

$(window).bind('popstate', function(e){ 
    // Prevent popstate handler dealing with initial page load 
    if (location.pathname == initialPath) { 
     initialPath = null; 
     return; 
    } 
    container.append(overlay); 
    $.get(location.pathname, { format: 'html' }, function(data){ 
     container.html(data); 
    }, 'html'); 
}); 
}); 

還添加此代碼添加到我的控制器

public function init(){ 
$this->_helper->ajaxContext->addActionContext('calllogs', 'html') 
          ->initContext(); 
} 

現在我collogs.phtml看起來像這樣

<?php 
include_once("header.phtml"); 
include_once("blue1.phtml"); 
include_once("sidebar.phtml"); 
?> 
<div id="paged-data-container"> 
<?php echo $this->render('login/calllogs_page.phtml') ?> 
</div> 
<?php include_once("footer.phtml"); ?> 

這是我的calllogs_page.phtml

<?php $paginationControl = $this->paginationControl(
$this->paginator, 'All', 'pagination.phtml') ?> 
    old stuff here 
<div class="pagination-control"> 
      <div class="fg-toolbar ui-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix" style="height:35px"> 
      <?php if (count($this->paginator)): ?> 
      <div class="dataTables_info" style="float:left;"> Showing <?= $this->A; ?> to <?= $this->B; ?> of <?=$this->C; ?> entries </div> 
      <div class="pagination-control" style="margin-left:173px;"> 
       <?php echo $paginationControl ?> 
       </div> 

現在我的頁面在地址欄中改變當過我的任何分頁鏈接點擊,但沒有任何反應比

這是

$(function($){ 
$('.pagination-control').find('a').live('click', function(){ 
    var link = $(this); 

    var container = link.parents('.paged-data-container'); 
    $.get(link.attr('href'), { format: 'html' }, function(data){ 
     container.html(data); 
    }, 'html'); 

    return false; 
}); 
}); 

回答

1

按照這些教程jquery的:Zend framework video tutorials

從視頻11 Zend_Paginator開始介紹。稍後它會被修改爲在其他視頻中使用Ajax。 我真的建議你看看它。