4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ページャークラスの使い方

Last updated at Posted at 2013-06-25
<?php
//ページャー
//ページの要素数がない場合
if(!isset($_POST["itemnum"])){ $_POST["itemnum"] = 20; }
//ページ番号がない場合
if(!isset($_POST["pagenum"])){ $_POST["pagenum"] = 1; }
//ページ番号からスタート値を取得
$pagestart = ($_POST["pagenum"] - 1) * $_POST["itemnum"];
?>
<?php
//limitを追加する前に全体数の取得
$count = Model::findAllBy("thread",$search);

//ページャー 現在のページ番号($pagenum)と要素数($itemnum)を受け取ってページャークラスを返す
$pager = PagerFactory::Create($count,$_POST["itemnum"],$_POST["pagenum"]);
//ページャークラスをViewに渡す
$out["pager"] = $pager;
?>

Twitter Bootstrap使用(↓こうなるよ)
bootstrap_pager.PNG

<form name="projectlist" method="post">
<input type="hidden" name="pagenum" value="<?php if(isset($out["pager"])){ htmlout($out["pager"]->getPagenum()); } ?>" />
<input type="hidden" name="itemnum" value="<?php if(isset($out["pager"])){ htmlout($out["pager"]->getItem()); } ?>" />
</form>
        
<div class="pagination pagination-centered" style="margin-top:0;margin-bottom:0;">
<ul>
<?php if($out["pager"]->getPrevpage()){ ?>
<li><a href="javascript:void(0)" onClick="f=document.projectlist;f.pagenum.value='<?php echo $out["pager"]->getPagenum() - 1; ?>';f.submit();">Prev</a></li>
<?php }else{ ?>
<li class="disabled"><a>Prev</a></li>
<?php } ?>
<?php for($p=1;$p<=$out["pager"]->getLastpage();$p++){ ?>
<?php if($p == $out["pager"]->getPagenum()){ ?>
<li class="active"><a><?php echo $p; ?></a></li>
<?php }else{ ?>
<li><a href="javascript:void(0)" onClick="f=document.projectlist;f.pagenum.value='<?php echo $p; ?>';f.submit();"><?php echo $p; ?></a></li>
<?php } ?>
<?php } ?>
<?php if($out["pager"]->getNextpage()){ ?>
<li><a href="javascript:void(0)" onClick="f=document.projectlist;f.pagenum.value='<?php echo $out["pager"]->getPagenum() + 1; ?>';f.submit();">Next</a></li>
<?php }else{ ?>
<li class="disabled"><a>Next</a></li>
<?php } ?>
</ul>
</div>
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?