Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I noticed you set <code>index.phtml</code> as your default view partial, to misquote a quote ... <em>I don't think that method does what you think it does.</em></p> <p>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.</p> <pre><code>public function indexAction(){ $params = array('host' =&gt;'localhost', 'username' =&gt;'root', 'password' =&gt;'', 'dbname' =&gt;'test' ); $db = new Zend_Db_Adapter_Pdo_Mysql($params); $select = $db-&gt;select()-&gt;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-&gt;setCurrentPageNumber($this-&gt;_getParam('page', 1)); $paginator-&gt;setItemCountPerPage(10); //assign paginator to the view $this-&gt;view-&gt;paginator=$paginator; } </code></pre> <p><strong>A note on adapters.</strong></p> <p>The biggest <em>apparent</em> difference between the adapters <code>Zend_Paginator_Adapter_DbTable</code> and <code>Zend_Paginator_Adapter_DbTableSelect</code> is that <em>DbTable</em> returns an aray will use the array notation <code>$item['name']</code> and <em>DbTableSelect</em> returns an object (rowset object) uses object notation `$item->name' so use the adapter appropriate to your needs.</p> <p>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 <a href="http://framework.zend.com/manual/1.12/en/zend.paginator.usage.html#zend.paginator.usage.rendering.example-controls" rel="nofollow">example</a>.</p> <p>Try this in your view.</p> <pre><code>&lt;!-- assumes you using DbTableSelect paginator adapter --&gt; &lt;!-- for DbSelect adapter just change to array notation: $item['id'] --&gt; &lt;table border=1&gt; &lt;?php foreach ($this-&gt;paginator as $item) : ?&gt; &lt;tr&gt; &lt;td&gt;&lt;?php echo $this-&gt;escape($item-&gt;id) ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $this-&gt;escape($item-&gt;name) ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $this-&gt;escape($item-&gt;city) ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $this-&gt;escape($item-&gt;state) ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $this-&gt;escape($item-&gt;date) ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $this-&gt;escape($item-&gt;zip) ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;?php endForeach ?&gt; &lt;?php echo $this-&gt;paginationControl($this-&gt;paginator,'Sliding','MyPaginatorControl.phtml'); ?&gt; </code></pre> <p>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 <code>views/scripts</code>) :</p> <pre><code>&lt;?php echo $this-&gt;paginationControl( //remember the third parameter is the controls partial $this-&gt;paginator, 'Sliding', '_paginatorControl.phtml' ) ?&gt; </code></pre> <p>Just in case someone needs it here is my basic control partial:</p> <pre><code>//views/scripts/_paginatorControl.phtml. Yes. I just copy this file to where ever I need it. &lt;?php if ($this-&gt;pageCount) : //you need to add each of the request parameters to url $params = Zend_Controller_Front::getInstance() -&gt;getRequest()-&gt;getParams(); //remove the system parameters unset($params['module']); unset($params['controller']); unset($params['action']); ?&gt; &lt;div class="paginationControl"&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt; &lt;!--First Page Link --&gt; &lt;?php if (isset($this-&gt;first)): ?&gt; &lt;a href="&lt;?php echo $this-&gt;url(array_merge($params, array('page' =&gt; $this-&gt;first))) ?&gt;"&gt; &amp;lt; First&lt;/a&gt; &lt;?php else : ?&gt; &lt;span class="disabled"&gt;&amp;lt; First&lt;/span&gt; &lt;?php endif ?&gt; &lt;/td&gt; &lt;td class="space"&gt;|&lt;/td&gt; &lt;td&gt; &lt;!--Previous Page Links--&gt; &lt;?php if (isset($this-&gt;previous)) : ?&gt; &lt;a href="&lt;?php echo $this-&gt;url(array_merge($params, array('page' =&gt; $this-&gt;previous))) ?&gt;"&gt; &amp;lt; Prev&lt;/a&gt; &lt;?php else : ?&gt; &lt;span class="disabled"&gt;&amp;lt; Prev&lt;/span&gt; &lt;?php endif ?&gt; &lt;/td&gt; &lt;td&gt;| &lt;!--Number page links--&gt; &lt;?php foreach ($this-&gt;pagesInRange as $page): ?&gt; &lt;?php if ($page != $this-&gt;current) : ?&gt; &lt;a href="&lt;?php echo $this-&gt;url(array_merge($params, array('page' =&gt; $page))) ?&gt;"&gt; &lt;?php echo $page ?&gt;&lt;/a&gt; | &lt;?php else: ?&gt; &lt;?php echo $page ?&gt; | &lt;?php endif; endforeach; ?&gt; &lt;/td&gt; &lt;td&gt; &lt;!--Next page link--&gt; &lt;?php if (isset($this-&gt;next)) : ?&gt; &lt;a href="&lt;?php echo $this-&gt;url(array_merge($params, array('page' =&gt; $this-&gt;next))) ?&gt;"&gt; Next &amp;gt;&lt;/a&gt; &lt;?php else : ?&gt; &lt;span class="disabled"&gt;Next &amp;gt;&lt;/span&gt; &lt;?php endif; ?&gt; &lt;/td&gt; &lt;td class="space"&gt;|&lt;/td&gt; &lt;td&gt; &lt;!--Last page Link --&gt; &lt;?php if (isset($this-&gt;last)): ?&gt; &lt;a href="&lt;?php echo $this-&gt;url(array_merge($params, array('page' =&gt; $this-&gt;last))) ?&gt;"&gt; Last &amp;gt;&lt;/a&gt; &lt;?php else: ?&gt; &lt;span class="disabled"&gt;last &amp;gt;&lt;/span&gt; &lt;?php endif ?&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; &lt;?php endif; ?&gt; </code></pre> <p>I hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload