index.phtml
引用を誤って引用するために、デフォルトのビューを部分的に設定していることに気づきました...そのメソッドはあなたが思っていることを実行するとは思いません。
少なくとも最初は、すべてを指定することをお勧めします。select()を指定し、アダプターを指定して、新しいページネーターを作成します。後でショートカットを取ることができます。
public function indexAction(){
$params = array('host' =>'localhost',
'username' =>'root',
'password' =>'',
'dbname' =>'test'
);
$db = new Zend_Db_Adapter_Pdo_Mysql($params);
$select = $db->select()->from('tableviewdemo');
//specify paginator adapter
$adapter = new Zend_Paginator_Adapter_DbTableSelect($select);
//instantiate the paginator
$paginator = new Zend_Paginator($adapter);
//if you really have to use the factory, don't forget the string for the adapter.
//The paginator should work without the string, but may not work as expected.
//$paginator = Zend_Paginator::factory($select, 'DbTableSelect');
$paginator->setCurrentPageNumber($this->_getParam('page', 1));
$paginator->setItemCountPerPage(10);
//assign paginator to the view
$this->view->paginator=$paginator;
}
アダプターに関する注意。
アダプター間の最大の明らかな違いは、 DbTableが配列表記を使用してarayを返し、 DbTableSelectがオブジェクト(行セットオブジェクト)がオブジェクト表記 `$ item-> name'を使用することを返すため、ニーズに適したアダプターを使用することです。Zend_Paginator_Adapter_DbTable
Zend_Paginator_Adapter_DbTableSelect
$item['name']
私の元のポイントに戻るために。デフォルトのビューパーシャルは、表示するページを参照していません。これは、ページネーターのコントロールを含むビューパーシャルを指します。Zendには、単なる例として、ページ付けコントロールのデフォルトの実装はありません。
あなたの見解でこれを試してください。
<!-- assumes you using DbTableSelect paginator adapter -->
<!-- for DbSelect adapter just change to array notation: $item['id'] -->
<table border=1>
<?php foreach ($this->paginator as $item) : ?>
<tr>
<td><?php echo $this->escape($item->id) ?></td>
<td><?php echo $this->escape($item->name) ?></td>
<td><?php echo $this->escape($item->city) ?></td>
<td><?php echo $this->escape($item->state) ?></td>
<td><?php echo $this->escape($item->date) ?></td>
<td><?php echo $this->escape($item->zip) ?></td>
</tr>
</table>
<?php endForeach ?>
<?php echo $this->paginationControl($this->paginator,'Sliding','MyPaginatorControl.phtml'); ?>
私が通常使用するページネーターは、マニュアルの例と非常によく似ており、ビュースクリプトで呼び出します(すべての部分ビューのデフォルトの場所はviews/scripts
):
<?php
echo $this->paginationControl(
//remember the third parameter is the controls partial
$this->paginator, 'Sliding', '_paginatorControl.phtml'
)
?>
誰かがそれを必要とする場合に備えて、ここに私の基本的なコントロールがあります:
//views/scripts/_paginatorControl.phtml. Yes. I just copy this file to where ever I need it.
<?php
if ($this->pageCount) :
//you need to add each of the request parameters to url
$params = Zend_Controller_Front::getInstance()
->getRequest()->getParams();
//remove the system parameters
unset($params['module']);
unset($params['controller']);
unset($params['action']);
?>
<div class="paginationControl">
<table>
<tr>
<td>
<!--First Page Link -->
<?php if (isset($this->first)): ?>
<a href="<?php
echo $this->url(array_merge($params, array('page' => $this->first)))
?>">
< First</a>
<?php else : ?>
<span class="disabled">< First</span>
<?php endif ?>
</td>
<td class="space">|</td>
<td>
<!--Previous Page Links-->
<?php if (isset($this->previous)) : ?>
<a href="<?php
echo $this->url(array_merge($params, array('page' => $this->previous)))
?>">
< Prev</a>
<?php else : ?>
<span class="disabled">< Prev</span>
<?php endif ?>
</td>
<td>|
<!--Number page links-->
<?php foreach ($this->pagesInRange as $page): ?>
<?php if ($page != $this->current) : ?>
<a href="<?php
echo $this->url(array_merge($params, array('page' => $page)))
?>">
<?php echo $page ?></a> |
<?php else: ?>
<?php echo $page ?> |
<?php
endif;
endforeach;
?>
</td>
<td>
<!--Next page link-->
<?php if (isset($this->next)) : ?>
<a href="<?php
echo $this->url(array_merge($params, array('page' => $this->next)))
?>">
Next ></a>
<?php else : ?>
<span class="disabled">Next ></span>
<?php endif; ?>
</td>
<td class="space">|</td>
<td>
<!--Last page Link -->
<?php if (isset($this->last)): ?>
<a href="<?php
echo $this->url(array_merge($params, array('page' => $this->last)))
?>">
Last ></a>
<?php else: ?>
<span class="disabled">last ></span>
<?php endif ?>
</td>
</tr>
</table>
</div>
<?php endif; ?>
これがお役に立てば幸いです。