0

所以我需要这样的东西:

上一页 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 下一页

请帮忙!

4

3 回答 3

0

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

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

于 2012-07-24T08:02:01.100 回答
0

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

于 2012-07-24T08:00:26.227 回答
0

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

页面.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>';
}

?>

样式.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;
}
于 2012-07-25T18:59:04.083 回答