0

我有一些分页问题。分页中的页码不起作用。我无法在 result.phtml 文件中获取页面编号。它总是在 1 上显示页面,而不是更新到下一页或上一页。

我正在将 zend 与 jquery 和 ajax 一起使用。请帮我...

我使用的文件是: 1. result.phtml 2. search-result-ajax.phtml 3. 控制器文件 4. 模块文件。

1. result.phtml 的代码:

    <script type="text/javascript">

    $(document).ready(function(){
    //var search_keyword = urlencode($("#search_keyword").val());
    var search_keyword = '<?php echo urlencode(str_replace("/", "-",$this->search_keyword)); ?>';
    $("#search_keyword").val('<?php echo addslashes($this->search_keyword); ?>');   

        //Display Loading Image
        function Display_Load()
        {
            $("#loading").fadeIn(900,0);
            $("#loading").html("<img src='<?php echo PUBLIC_URL; ?>images/bigLoader.gif' />");
        }
        //Hide Loading Image
        function Hide_Load()
        {
            $("#loading").fadeOut('slow');
        };


        //Default Starting Page Results

        $("#pagination li:first").css({'color' : '#FFFFFF'}).css({'font-weight' : 'bold'}).css({'border' : 'solid #dddddd 1px'}).css({'background' : '#01367A'});

        Display_Load();

        $("#Pagecontent").load("<?php echo $this->baseUrl; ?>/catalogsearch/search-result-ajax/search_keyword/"+search_keyword+"/page/1", Hide_Load());

         //Pagination Click
        $("#pagination li").click(function(){

            Display_Load();

            $("#pagination li")
            .css({'border' : 'solid #dddddd 1px'})
            .css({'font-weight' : 'bold'})
            .css({'color' : '#0063DC'})
            .css({'background' : 'none'});

            $(this)
            .css({'color' : '#FFFFFF'})
            .css({'font-weight' : 'bold'})
            .css({'border' : 'solid #dddddd 1px'})
            .css({'background' : '#01367A'});

            //Loading Data
            var pageNum = this.id;

            alert(pageNum);

            $("#Pagecontent").load("<?php echo $this->baseUrl; ?>/catalogsearch/search-result-ajax/search_keyword/"+search_keyword+"/page/" + pageNum, Hide_Load());
            $('body,html').animate({
            scrollTop: 0
            }, 2000);
            return false;
        });

    });

    function urlencode (str) {
        str = (str + '').toString();

    // Tilde should be allowed unescaped in future versions of PHP (as reflected below), but if you want to reflect current
    // PHP behavior, you would need to add ".replace(/~/g, '%7E');" to the following.
    return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
   }

</script>
<!--STARTS:Content Outer Div-->
<div id="main_outer">
  <!--STARTS:Content Inner Div-->
  <div id="main_inner">

        <!--STARTS:Breadcrumbs Div-->
        <div class="bread_crumb">
            <a style="" href="<?php echo $this->baseUrl; ?>/">Home</a><?php echo $this->searchResultText;?>
            <div class="clboth"></div>
        </div>
        <!--END:Breadcrumbs Div-->

        <!-- STARTS: Body Content Div-->
        <div class="content_div">

        <?php echo $this->renderPath(COMMON_HTML.'left_column.phtml'); ?>
        <!--STARTS:Content Right Column Div-->
        <div class="rt_col">
            <p><?php echo nl2br($this->cmsData[0]['content']);?></p>
            <h1> <?php echo $this->searchResultText;?></h1>
                        <?php if(count($this->productData)>0){?>
                        <div style="float:right;margin-right:10px;"><h4><?php echo count($this->productData);?> Results Found.</h4></div>
                        <?php }?>
                        <br>   
            <div id="content-top"><br>
                 <?php if(count($this->productData)>0){?>
                                        <div class="upcoming_events">
                                            <h2>Search Result</h2>

                                            <div class="list">
                                                <div class="date"><strong>Date</strong></div>
                                                <div class="conference"><strong>Conference </strong></div>
                                                <div class="speaker"><strong>Speaker </strong></div>
                                                <div class="price"><strong>Price</strong></div>
                                                <div class="btn">&nbsp;</div>
                                            </div>
                                            <div id="Pagecontent"><div style="text-align:center"><img src="<?php echo PUBLIC_URL; ?>images/bigLoader.gif"></div></div>

                                            <?php
                                                $count = count($this->productData);
                                                $per_page = PAGECOUNT;
                                                $numofpages = ceil($count/$per_page);
                                                $lastpage = ceil($count/$per_page);
                                                $page=$_POST['page'];                                                
                                            ?>

                                                <div class="list" style="float:right;">
                                                <ul id="pagination">

                                                <?php
                                                //Show page links

                                                if (!(isset($page))) 
                                                     $page = 1; 

                                                if ($page < 1) 
                                                    $page = 1; 
                                                elseif ($page > $lastpage) 
                                                    $page = $lastpage; 

                                                if ($page == 1)
                                                { 
                                                   echo '<li class="pageli">'."First".'</li>';
                                                   echo '<li class="pageli">'."Prev".'</li>';
                                                }
                                                else 
                                                {

                                                   echo '<li id="'.$page.'" class="pageli">'."First".'</li>';
                                                   $page = $page-1;
                                                   echo '<li id="'.$page.'" class="pageli">'."Prev".'</li>';
                                                }

                                                echo '<li class="pageli">'."Page ".$page." of ".$lastpage.'</li>';

                                                if ($page == $lastpage) 
                                                {
                                                    echo '<li class="pageli">'."Next".'</li>';
                                                    echo '<li class="pageli">'."Last".'</li>';
                                                }
                                                else 
                                                {
                                                   $page = $page+1;

                                                   $page=$page+'?page'+$page;
                                                   echo '<li id="'.$page.'"     class="pageli">'."Next".'</li>';
                                                   echo '<li id="'.$lastpage.'" class="pageli">'."Last".'</li>';
                                                } 
                                               /* for($i=1; $i<=$numofpages; $i++){

                                                    echo '<li id="'.$i.'" class="pageli">'.$i.'</li>';
                                                } */
                                                ?>
                                                </ul>
                                                </div>

                                                <div class="upcomingevents_list clboth">
                                                <span class="floatrt pdleft5">denotes hot selling conferences per customer preference</span>
                                                <img src="<?php echo PUBLIC_URL;?>images/star_orange.gif" alt="" title="" class="floatrt">
                                                </div>


                                        </div>

                                        <?php
                                        }else{
                                        echo "<div id='' style='text-align:center;padding-top:30px;'><h2>No record Found</h2></div>";
                                        }
            ?>

            </div>


        </div>
        <!--END:Content Right Column Div-->
    </div>
    <!-- END: Body Content Div-->
  </div>
  <!--END:Content Inner Div-->
</div>
<!--END:Content Outer Div-->

search-result-ajax.phtml 的代码:

<div id="paginationDiv">  
<?php

if(count($this->paginator)> 0 ){
$i=1;
foreach($this->paginator as $key=>$value){
  if($value['is_hot']=='1'){
      $star = '<div class="star" title="Hot Product">&nbsp;</div>';
  }else{
     $star = '<div class="star_white">&nbsp;</div>';
  }
  if($i%2==0){$class='upcoming_events_list_white';}else{$class='upcoming_events_list_grey';}

  if($value['cat_url'] !="") $url = $this->baseUrl."/".$value['cat_url']."/".$value['url_key'].'.html';
  else $url = $this->baseUrl."/".$value['url_key'].'.html';

  $cdate = strtotime(date("Y-m-d"));
  $tdate = strtotime($value['broadcast_date_to']);

  if(($value['broadcast_date_to']!="" && $value['broadcast_date_to']!="0000-00-00") && ($tdate >= $cdate)){
      $Data = date("M j, Y",strtotime($value['broadcast_date_to'])); 
  }else if(($value['conference_date']!="" && $value['conference_date']!="0000-00-00")){
      $Data = date("M j, Y",strtotime($value['conference_date']));  
  }else{
      $Data = "";
  }
?>

<div class="<?php echo $class;?>">
<div class="date"><?php echo $Data;?></div>
<div class="conference"><a title="<?php echo utf8_encode($value['name']);?>" href="<?php echo $url; ?>"><?php $name = utf8_encode($value['name']); if(strlen(utf8_encode($name)) > 50 ) { echo substr($name,0, 50).'..';}else{echo $name;}; ?></a></div>
<div class="speaker"><?php echo ucfirst($value['presenter_fname']." ".$value['presenter_lname']); ?></div>
<div class="price">$<?php if($value['price'] > 0 ) {echo $value['price'];}else echo '197.00'; ?></div>
<div class="btn"><a href="<?php echo $url; ?>" class="img_btn">Buy Now</a></div>
 <?php echo $star;?>
</div>
<?php 
$i++;

}

} 
?>
 </div>

控制器文件的代码:

function resultAction() 
{

    if(trim($_GET['q'])){
      $searchKeyword = urldecode($_GET['q']);  
    }else{
        $PostData = $this->_request->getPost();
        $searchKeyword = $PostData['search_keyword'];
    }
    $this->view->search_keyword = $searchKeyword;
    $this->view->pageTitle="Search results for: '".$searchKeyword."'";
    $this->view->searchResultText="Search results for: '".$searchKeyword."'";

    $productData = $this->productObj->searchProduct(array('search_keyword' => addslashes(str_replace("/","-",$searchKeyword)),
                                                       'orderField'=>'conference_date',
                                                       'orderType'=>'DESC'));

     $this->searchtrackObj = new Models_SearchKeywordTracking();
     if(count($productData)>0){
        $this->view->productData = $productData;

    $this->view->page=$PostData['page'];
    $result = $this->searchtrackObj->search_by_keyword(trim(addslashes($searchKeyword)));

    $data = array();
    if(count($result)==0){

        $data['query_text'] = trim($searchKeyword);
        $data['num_results'] = count($productData);
        $data['popularity'] = 1;
        $data['updated_at'] = date('Y-m-d H:i:s');

        $this->searchtrackObj->addData($data);
    }else{
        $data['query_text'] = trim($searchKeyword);
        $data['num_results'] = count($productData);
        $data['popularity'] = ($result['0']['popularity']+1);
        $data['updated_at'] = date('Y-m-d H:i:s');
        $this->searchtrackObj->updateData($data,"query_id='".$result['0']['query_id']."'");

        }
        }
}

function searchResultAjaxAction() 
{

    $this->_helper->layout()->disableLayout();   
    $PostData = $this->_request->getParams();

    $this->view->page=$PostData['page'];

    $searchKeyword = urldecode($PostData['search_keyword']);

    $this->view->search_keyword = $searchKeyword;

    $productData = $this->productObj->searchProduct(array('search_keyword' => addslashes($searchKeyword),'searchresult'=>true));

     $this->paginator($productData);
}

模块文件的代码

function paginator($content, $range=PAGECOUNT) 
{
    $paginator = Zend_Paginator::factory($content);
    $page = $this->_getParam('page', 1);
    $paginator->setCurrentPageNumber($page);
    $paginator->setItemCountPerPage($range);
    //$paginator->setPageRange(11);
    $this->view->page_num = $page;
    $this->view->paginator = $paginator;
    $this->view->countperpage = $range;
    $this->view->page = $page;
    return true;
}

请帮我解决这个问题

谢谢。

4

1 回答 1

0

结果,您试图从中获取页面的值$_POST

$page=$_POST['page'];

但是您正在通过发送页面参数GET

$("#Pagecontent").load("<?php echo $this->baseUrl; ?>/catalogsearch/search-result-ajax/search_keyword/"+search_keyword+"/page/" + pageNum, Hide_Load()); 

我认为这就是问题所在。

于 2013-07-05T17:16:53.133 回答