给按数据集分类增加了分页功能

This commit is contained in:
Li Jianxuan 2011-09-21 08:35:03 +00:00
parent 6a08ef80bc
commit 3cf6a50ff3
3 changed files with 84 additions and 39 deletions

View File

@ -312,7 +312,14 @@ class DataController extends Zend_Controller_Action
$this->view->codename=(empty($row->name_zh)?$row->name:$row->name_zh); $this->view->codename=(empty($row->name_zh)?$row->name:$row->name_zh);
$sql='select m.* from metadata m,category c where m.id=c.id and c.code=? order by m.title'; $sql='select m.* from metadata m,category c where m.id=c.id and c.code=? order by m.title';
$state=$db->query($sql,array($code)); $state=$db->query($sql,array($code));
$this->view->metadata = $state->fetchAll(); $rows = $state->fetchAll();
$paginator = Zend_Paginator::factory($rows);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(10);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
} else { } else {
//提供全部分类列表 //提供全部分类列表
} }

View File

@ -24,16 +24,28 @@ $this->breadcrumb()->setSeparator(' > ');
</ul></fieldset> </ul></fieldset>
</div> </div>
<div id='metacontent'> <div id='metacontent'>
<?php if (!empty($this->metadata)) : ?>
<h1>当前浏览分类:<?php echo $this->codename; ?></h1> <?php if (count($this->paginator)): ?>
<?php foreach($this->metadata as $md) : ?> <?php
<hr /> $i=0;
<div class="mditem"> foreach ($this->paginator as $item):
<div class="thumb"><img src="/data/thumb/id/<?php echo $md['id'];?>" /></div> $i++;
<h2><a href="/data/<?php echo $md['uuid']; ?>"><?php echo $this->escape($md['title']);?></a> if (mb_strlen($item['description'])>700)
{
$item['description'] = mb_substr($item['description'],0,400,'UTF-8').'...';
}
if($i%2==0) $style="style='background:#fafafa;'";
else $style="";
echo '<div class="mditem" '.$style.'>
<div class="thumb"><img src="/data/thumb/id/'.$item['id'].'" /></div>
<h2><a href="/data/'.$item['uuid'].'">'.$this->escape($item['title']).'</a>
</h2> </h2>
<span><?php echo mb_strlen($md['description'])>400?$this->escape(mb_substr($md['description'],0,400,'UTF-8').'...'):$this->escape($md['description']);?></span> <p>'.$item['description'].'</p>
</div> </div>';
<?php endforeach; endforeach;
endif; ?> ?>
<?php endif; ?>
<?= $this->paginator; ?>
</div> </div>

View File

@ -0,0 +1,26 @@
<?php if ($this->pageCount): ?>
<div class="paginationControl">
<!-- Previous page link -->
<?php if (isset($this->previous)): ?>
<a href="<?= $this->url(array('page' => $this->previous)); ?>?<?php echo $_SERVER["QUERY_STRING"];?>">&lt; Previous</a>
<?php else: ?>
<span class="disabled">&lt; 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)); ?>?<?php echo $_SERVER["QUERY_STRING"];?>"><?= $page; ?></a>
<?php else: ?>
<span class="current"><?= $page; ?></span>
<?php endif; ?>
<?php endforeach; ?>
<!-- Next page link -->
<?php if (isset($this->next)): ?>
<a href="<?= $this->url(array('page' => $this->next)); ?>?<?php echo $_SERVER["QUERY_STRING"];?>">Next &gt;</a>
<?php else: ?>
<span class="disabled">Next &gt;</span>
<?php endif; ?>
</div>
<?php endif; ?>