【问题标题】:Paginator, how to make the first page and the last static and puts to dots between分页器,如何使第一页和最后一页静态并在之间放置点
【发布时间】:2012-07-26 03:05:43
【问题描述】:

所以我需要这样的东西:

上一个 1 ... 5 6 7 8 ... 56 下一个

这是我的看法:

<?php if ($this->pageCount>1):?>
<div class="paginator">

<!-- Ссылка на предыдущую страницу -->
<?php if (isset($this->previous)): ?>
  <a class="next" href="<?php echo $this->url(array( 'id' => $this->element_id,'sortby'=>$this->sortby,'page' => $this->previous), $this->route.'_pagination'); ?>">
     <?=$this->translator()->_('previous');?>
  </a>
<?php endif; ?>
<!-- Нумерованные ссылки на страницы -->
<?php foreach ($this->pagesInRange as $page): ?>
  <?php if ($page != $this->current): ?>
    <a class="numbers" href="<?php echo $this->url(array( 'id' => $this->element_id,'sortby'=>$this->sortby, 'page' => $page), $this->route.'_pagination'); ?>">
        <?php echo $page; ?>
    </a>
  <?php else: ?>
        <a class="active" href="#"><?php echo $page; ?></a>
  <?php endif; ?>
<?php endforeach; ?>

<!-- Ссылка на следующую страницу -->
<?php if (isset($this->next)): ?>
  <a class="prev" href="<?php echo $this->url(array( 'id' => $this->element_id,'sortby'=>$this->sortby,'page' => $this->next), $this->route.'_pagination'); ?>">
    <?=$this->translator()->_('next');?>
  </a>
<?php endif; ?>

</div>
<?php endif; ?>

这是我的控制器,功能索引:

public function indexAction()
{
        if ($this->getRequest()->isXmlHttpRequest()) $this->_helper->layout->disableLayout();
    $mapper = new Album_Model_Mapper_Album();
    $user_id = $this->_request->getParam('id');

        $adapter = new Zend_Paginator_Adapter_DbSelect($mapper->getUserAlbums($user_id));

        $paginator = new Zend_Paginator($adapter);
        $settings = $this->getFrontController()->getParam('bootstrap')->getOption('settings');
        $paginator->setCurrentPageNumber($this->_getParam('page'));
        $paginator->setItemCountPerPage($settings['albums_per_page_profile']);
        $paginator->setPageRange(4);
        $this->view->route = 'albums';
        $this->view->paginator = $paginator;
    $this->view->user_id = $user_id;
    $this->view->current_page = $this->_getParam('page') ? $this->_request->getParam('page') : 1;
    if((!isset($this->view->current_page) or $this->view->current_page==1) and $user_id==$this->getStorage()->read()->id){
        $mapperFilters = new Filters_Model_Mapper_PhotoFilters();
        $this->view->filter = $mapperFilters->fetchBySql($mapperFilters->getUserPhotos($this->getStorage()->read()->id)->limit(1), true, true);
    }
    echo $this->view->render('albums.phtml');

}

现在我有这样的东西:

上一页 2 3 4 5 下一页

我不知道怎么改成这样:

上一个 1 ... 5 6 7 8 ... 56 下一个

请帮忙!

【问题讨论】:

    标签: php html css zend-framework pagination


    【解决方案1】:

    您可以使用我自己创建的分页类,其中只更改第一个和最后一个更改的名称,您可以只更改一些模式。 另外,如果您对如何使用课程有疑问,请与我联系。 http://danielspitkevics.id.lv/index.php?r=site/viewscripts&id=10

    【讨论】:

      【解决方案2】:

      如果你愿意更换你的分页类并使用一个新的,这个会完全符合你的要求:

      http://www.catchmyfame.com/2007/07/28/finally-the-simple-pagination-class/

      【讨论】:

        【解决方案3】:

        您可以从以下脚本中获得帮助,我主要用于分页工作。

        page.php

        <?php
           include('db_connect.php');   // include your code to connect to DB.
           $page_id = isset($_GET['page_id']) ? $_GET['page_id'] : 1;
           $tbl_name="city";        //your table name
           $records_per_page = 5;
        
           /* Pagination Starts here */
           $query = "SELECT * FROM $tbl_name";
           $result= mysql_query($query);
        
           if($page_id==1)
           {
            $start_id=0;
            $end_id=$records_per_page;
           }
           else
           {
            $start_id=$records_per_page*($page_id-1);
            $end_id=$records_per_page*$page_id;
           }
        
           $start_limit = mysql_num_rows($result)-1 - $start_id;
           if($end_id>mysql_num_rows($result))
            $end_limit = 0;
           else
            $end_limit = mysql_num_rows($result)-$end_id;
        
           $select_limit=$start_limit-$end_limit+1;
        
           for ($i = $start_limit,$j=0; $i >= $end_limit; $i--,$j++) 
           {
            if(!mysql_data_seek($result, $i)) 
            {
            echo "Cannot seek to row $i: " . mysql_error() . "\n";
            continue;
            }
        
            if (!($row = mysql_fetch_assoc($result))) 
            {
            continue;
            }
        
           // your code to print data, i have echo city name from city table.
            echo $row['city_name'].'<br>';
           }
        
           if(mysql_num_rows($result))
           {
        $temp=(int)(mysql_num_rows($result)/$records_per_page);
        
        if($temp< (ceil((mysql_num_rows($result)/$records_per_page))))
            $total_pages=ceil((mysql_num_rows($result)/$records_per_page));
        else if($temp==floor((mysql_num_rows($result)/$records_per_page)))
            $total_pages=floor((mysql_num_rows($result)/$records_per_page));
        
        echo '<div class="pagination">';
        if($page_id==1)
        {
            echo '<span class="disabled" title="First Page"><<</span>';
            echo '<span class="disabled" title="Previous Page"><</span>';                   
        }
        else
        {
                echo '<a href="page.php?page_id=1" title="First Page"><<</a>';
                echo '<a href="page.php?page_id='.($page_id-1).'" title="Previous Page"><</a>';             
        }
        
        if($page_id<=5)
            $min = $page_id;
        else
            $min = $page_id-5;
        if($total_pages<($page_id+5))
            $max = $total_pages;
        else
            $max = $page_id+5;
        while($min<=$page_id)
        {
            if($min==$page_id)
                echo '<span class="current" title="Current Page">'.$page_id.'</span>';
            else
            {
                echo '<a href="page.php?page_id='.$min.'" title="Page '.$min.'">'.$min.'</a>';
            }
            $min++;
        }
        
            $i = $page_id +1;
        while($i<=$max)
        {
            echo '<a href="page.php?page_id='.$i.'" title="Page '.$i.'">'.$i.'</a>';
            $i++;
        }
        
        if($page_id==$total_pages)
        {
            echo '<span class="disabled" title="Next Page">></span>';
            echo '<span class="disabled" title="Last Page">>></span>';                  
        }
        else
        {
            echo '<a href="page.php?page_id='.($page_id+1).'" title="Next Page">></a>';
            echo '<a href="page.php?page_id='.$total_pages.'" title="Last Page">>></a>';
        }
        echo '</div>';
        }
        
        ?>
        

        style.css

            div.pagination {
            padding: 3px;
            margin: 3px;
        }
        
        div.pagination a {
            padding: 2px 5px 2px 5px;
            margin: 2px;
            border: 1px solid #AAAADD;
        
            text-decoration: none; /* no underline */
            color: #000099;
        }
        
        div.pagination a:hover, div.pagination a:active {
            border: 1px solid #000099;
            color: #000;
        }
        
        div.pagination span.current {
            padding: 2px 5px 2px 5px;
            margin: 2px;
                border: 1px solid #000099;
        
                font-weight: bold;
                background-color: #000099;
                color: #FFF;
            }
        div.pagination span.disabled {
            padding: 2px 5px 2px 5px;
            margin: 2px;
            border: 1px solid #EEE;
        
            color: #DDD;
        }
        

        【讨论】:

          猜你喜欢
          • 2021-06-06
          • 2018-01-24
          • 2020-07-10
          • 1970-01-01
          • 1970-01-01
          • 2021-05-14
          • 2016-08-10
          • 1970-01-01
          • 2014-08-20
          相关资源
          最近更新 更多