Php/zend framework/zend paginator
提供: 初心者エンジニアの簡易メモ
2015年5月20日 (水) 02:58時点における127.0.0.1 (トーク)による版 (ページの作成:「ページ送り require_once 'Zend/Paginator.php'; require_once 'Zend/Paginator/Adapter/Array.php'; // コンテンツを取得 $contents = Array(); // ページネ...」)
ページ送り
require_once 'Zend/Paginator.php';
require_once 'Zend/Paginator/Adapter/Array.php';
// コンテンツを取得
$contents = Array();
// ページネーションをロード
$paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Array($contents));
// 1ページあたりのアイテム数設定
$paginator->setItemCountPerPage(30);
// 表示ページ数
$paginator->setPageRange(10);
// 現在のページ設定
$paginator->setCurrentPageNumber($this->_getParam('page'));
// 現在のページのコンテンツ
$contentsPerPage = $paginator->getCurrentItems();
// ページ情報取得
$pages = $paginator->getPages();
// ビューへコンテンツを渡す
$this->view->contents = $contentsPerPage;
$this->view->pages = $pages;
Smartyテンプレート
ページ数:{{$pages->pageCount}}
1ページあたりのアイテム数:{{$pages->itemCountPerPage}}
最初のページ:{{$pages->first}}
現在のページ:{{$pages->current}}
最後のページ:{{$pages->last}}
前のページ:{{$pages->previous}}
次のページ:{{$pages->next}}
表示ページ中の最初のページ:{{$pages->firstPageInRange}}
表示ページ中の最後のページ:{{$pages->lastPageInRange}}
現在表示のアイテム数:{{$pages->currentItemCount}}
最後のアイテム:{{$pages->totalItemCount}}
現在のページの最初のアイテム:{{$pages->firstItemNumber}}
現在のページの最後のアイテム:{{$pages->lastItemNumber}}
Smartyテンプレート実践例
<center>
{{if $pages->pageCount}}
<!-- 前のページへのリンク -->
{{if $pages->previous}}
{{if $pages->previous == 1}}
<a href="/{{$controller|escape}}">≪</a>
{{else}}
<a href="/{{$controller|escape}}/{{$pages->previous}}">≪</a>
{{/if}}
{{else}}
<span class="disabled">≪</span>
{{/if}}
<!-- /前のページへのリンク -->
<!-- ページ番号へのリンク -->
{{foreach item=page from=$pages->pagesInRange}}
{{if $page != $pages->current}}
{{if $page == 1}}
<a href="/{{$controller|escape}}">{{$page}}</a>
{{else}}
<a href="/{{$controller|escape}}/{{$page}}">{{$page}}</a>
{{/if}}
{{else}}
{{$page}}
{{/if}}
{{/foreach}}
<!-- /ページ番号へのリンク -->
<!-- 次のページへのリンク -->
{{if $pages->next}}
<a href="/{{$controller|escape}}/{{$pages->next}}">≫</a>
{{else}}
<span class="disabled">≫</span>
{{/if}}
<!-- /次のページへのリンク -->
{{/if}}
</center>
