zend_paginator组件(二)

array

//controller/index

$array = array('测试1', '测试2','测试3','测试4','测试5','测试6','测试7','测试8','测试9','测试10','测试11','测试12','测试13','测试14','测试15','测试16','测试17','测试18','测试19','测试20',);
 $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Array($array));
 $paginator->setCurrentPageNumber($this->_getParam('page'));
$this->view->paginator = $paginator;
$this->render('index');

Zend_Db_Select

$db = Zend_Registry::get('db');
$select = $db->select();
$select->from('blog_article', '*');
$paginator = Zend_Paginator::factory($select);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setPageRange(5);
$this->view->paginator = $paginator;
$this->render('index');

view视图分tpl和phtml两种

为tpl格式

//index.tpl

<!-- 加载页面文档类型语句 -->
{$this->doctype()}
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>{$title}</title>

{$this->headLink()}
{$this->jQuery()}
{$this->headLink()}
</head>
<body>
<p align="center"><a href="{$baseUrl}/index/addui/">增加数据</a></p>
<table width="500px" border="1"  cellspacing="0" cellpadding="0" align="center">
    <thead>
      <tr align="center">
        <th colspan="4" height="30" bgcolor="#cccccc">数据列表显示</th>
      </tr>

    </thead>
    <tbody>
    <tr align="center">
        <th height="30">编号</th>
        <th height="30">标题</th>
        <th height="30">内容</th>
        <th height="30">操作</th>

    </tr>
   {if (count($this->paginator))}
   {foreach from=$paginator item=message}
   <tr align="center">
   	<td height="30">{$message.message_id}</td>
   	<td height="30">{$message.title}</td>
    <td height="30">{$message.content}</td>
    <td height="30"><a href="{$baseUrl}/index/editui/id/{$message.message_id}">编辑</a>/
       <a href="{$baseUrl}/index/del/id/{$message.message_id}">删除</a>
    </td>
   </tr> 
    {/foreach}
    {/if}
      </tbody>

    </table>
 
{$this->paginationControl($this->paginator, 'Sliding', '/global/pagination_control.tpl')}


</body>

</html>


//pagination_control.tpl

{if ($this->pageCount)} 
   <center>
    <table width="600"><tbody><tr>
    <!-- 第一页 -->
    <td><div id="prev"><a href=""><img src="/blog/images/bg1.jpg"></a></div></td>
    <!-- 上一页 -->
    {if (isset($this->previous))} 
     <td> <a href="$this->previous"><img src="/blog/images/bg2.jpg"></a></td>
    {/if} 
    <!-- 数字索引 -->
    {foreach from=$this->pagesInRange  item=page}

       {if ($page != $this->current)}
        <td width="20" id="indexclick"><a href="{$smarty.const.baseUrl}/page/{$page}">{$page}</a></td> 
      {else}
        <td width="20" id="indexclick"><font style="color: red;">{$page}</font></td>
      {/if}
    {/foreach}
    <!-- 下一页 -->
    {if (isset($this->next))} 
       <td><div id="prev"><a href=""><img src="/blog/images/bg3.jpg"></a></td> 
    {/if} 
    <!-- 最后一页 -->
    <td><a href=""><img src="/blog/images/bg4.jpg"></a></div></td>
    <td>总共{$this->pageCount}页 总共{$this->totalItemCount}条信息 <input type="text" size="4" name="pag"></td>
    <td><input type="hidden" value="" name="datee"><input type="hidden" value="" name="class"><input type="submit" value="确定"></td>
    </tr></tbody></table></center>
{/if}


 

 

为phtml格式时

//index.phtml

<html>
<body>
<h1>Example</h1>
<?php if (count($this->paginator)): ?>
<ul>
<?php foreach ($this->paginator as $item): ?>
   <li><?= $item['id']; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?= $this->paginationControl($this->paginator, 'Sliding', 'index/my_pagination_control.phtml'); ?>
</body>
</html>


 

 

//my_pagination_control.phtml

<?php if ($this->pageCount): ?> 
   <center>
    <table width="400"><tbody><tr>
    <!-- 第一页 -->
    <td><div id="prev"><a href="<?= $this->url(array('page' => $this->first)); ?>"><img src="<?= PUBLIC_PATH?>/blog/images/bg1.jpg"></a></div></td>
    <!-- 上一页 -->
    <?php if (isset($this->previous)): ?> 
     <td> <a href="<?= $this->url(array('page' => $this->previous)); ?>"><img src="<?= PUBLIC_PATH?>/blog/images/bg2.jpg"></a></td>
    <?php endif; ?> 
    <!-- 数字索引 -->
    <?php foreach ($this->pagesInRange as $page): ?>
       <?php if ($page != $this->current): ?>
        <td width="20" id="indexclick"><a href="<?= $this->url(array('page' => $page)); ?>"><?= $page; ?></a></td> 
      <?php else: ?>
        <td width="20" id="indexclick"><font style="color: red;"><?= $page; ?></font></td>
      <?php endif; ?>
    <?php endforeach; ?>
    <!-- 下一页 -->
    <?php if (isset($this->next)): ?> 
       <td><div id="prev"><a href="<?= $this->url(array('page' => $this->next)); ?>"><img src="<?php echo PUBLIC_PATH?>/blog/images/bg3.jpg"></a></td> 
    <?php endif; ?> 
    <!-- 最后一页 -->
    <td><a href="<?= $this->url(array('page' => $this->last)); ?>"><img src="<?php echo PUBLIC_PATH?>/blog/images/bg4.jpg"></a></div></td>
    <td>总共<?= $this->pageCount?>页  <input type="text" size="4" name="pag"></td>
    <td><input type="hidden" value="" name="datee"><input type="hidden" value="" name="class"><input type="submit" value="确定"></td>
    </tr></tbody></table></center>
<?php endif; ?>

你可能感兴趣的:(zend_paginator组件(二))