I noticed you set index.phtml
as your default view partial, to misquote a quote ... I don't think that method does what you think it does.
At least in the beginning I suggest you specify everything. Specify the select(), specify the adapter, create a new paginator. Later you can take the short cuts.
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;
}
A note on adapters.
The biggest apparent difference between the adapters Zend_Paginator_Adapter_DbTable
and Zend_Paginator_Adapter_DbTableSelect
is that DbTable returns an aray will use the array notation $item['name']
and DbTableSelect returns an object (rowset object) uses object notation `$item->name' so use the adapter appropriate to your needs.
To get back to my original point. The default view partial does not refer the page you want displayed. It refers to the view partial that contains the controls for your paginator. Zend does not have a default implementation of pagination controls just an example.
Try this in your view.
<!-- 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'); ?>
The paginator I typically use is very similar to the example in the manual, I call it in my view script (the default location for all partial views is views/scripts
) :
<?php
echo $this->paginationControl(
//remember the third parameter is the controls partial
$this->paginator, 'Sliding', '_paginatorControl.phtml'
)
?>
Just in case someone needs it here is my basic control partial:
//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; ?>
I hope this helps.