linkpager.php
2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
use yii\helpers\Html;
/*
First Previous 1 2 3 ... 22 23 24 25 26 [27] 28 29 30 31 32 ... 48 49 50 Next Last
*/
// Number of page links in the begin and end of whole range
$count_out = 2;
// Number of page links on each side of current page
$count_in = 2;
// Beginning group of pages: $n1...$n2
$n1 = 1;
$n2 = min($count_out, $total_pages);
// Ending group of pages: $n7...$n8
$n7 = max(1, $total_pages - $count_out + 1);
$n8 = $total_pages;
// Middle group of pages: $n4...$n5
$n4 = max($n2 + 1, $current_page - $count_in);
$n5 = min($n7 - 1, $current_page + $count_in);
$use_middle = ($n5 >= $n4);
// Point $n3 between $n2 and $n4
$n3 = (int) (($n2 + $n4) / 2);
$use_n3 = ($use_middle && (($n4 - $n2) > 1));
// Point $n6 between $n5 and $n7
$n6 = (int) (($n5 + $n7) / 2);
$use_n6 = ($use_middle && (($n7 - $n5) > 1));
// Links to display as array(page => content)
$links = array();
// Generate links data in accordance with calculated numbers
for ($i = $n1; $i <= $n2; $i++)
{
$links[$i] = $i;
}
if ($use_n3)
{
$links[$n3] = '…';
}
for ($i = $n4; $i <= $n5; $i++)
{
$links[$i] = $i;
}
if ($use_n6)
{
$links[$n6] = '…';
}
for ($i = $n7; $i <= $n8; $i++)
{
$links[$i] = $i;
}
?>
<?php
$length = isset($_COOKIE['paginationLength'])?$_COOKIE['paginationLength']:10;
if ($_POST && isset($_POST['paginationLength'])){
setcookie('paginationLength',$_POST['paginationLength']);
$length = $_POST['paginationLength'];
}
?>
<form action="" method="post" id="paginationForm">
<div class="colgroup">
<div class="width3 column first"><p>
每页 <?php echo Html::dropDownList('paginationLength',$length,array('10'=>10,'20'=>20,'40'=>40),array('id'=>'paginationSelect','style'=>'height:24px;font-size:12px;'))?> 项
第 <b><?php echo $current_first_item?>-<?php echo $current_last_item?></b> 项 总共 <b><?php echo $total_items?></b> 项
</p></div>
<div class="width3 column">
<p class="pagination ta-right">
<?php if ($current_page !== 1): ?>
<a href="<?php echo $page->createUrl(0) ?>">«</a>
<?php else: ?>
<span style="color:#CCCCCC;padding:2px 6px;">«</span>
<?php endif ?>
<?php foreach ($links as $number => $content): ?>
<?php if ($number === $current_page): ?>
<a href="javascript:void(0)" class="pagination-active"><?php echo $content ?></a>
<?php else: ?>
<a href="<?php echo $page->createUrl($number-1) ?>"><?php echo $content ?></a>
<?php endif ?>
<?php endforeach ?>
<?php if ($current_page !== $total_pages): ?>
<a href="<?php echo $page->createUrl($total_pages-1) ?>">»</a>
<?php else: ?>
<span style="color:#CCCCCC;padding:2px 6px;">»</span>
<?php endif ?>
</p>
</div>
</div>
<?php echo Html::hiddenInput(Yii::$app->getRequest()->csrfParam, Yii::$app->getRequest()->getCsrfToken());?>
</form>
<div class="clearfix"></div>
<hr />
<script type="text/javascript">
<!--
document.getElementById('paginationSelect').onchange = function(){
document.getElementById('paginationForm').submit();
};
//-->
</script>