【发布时间】:2015-02-01 20:50:22
【问题描述】:
我正在使用 Cakephp 2.x 尝试对我的模型索引之一进行分页。我已成功使用 Paginator 创建表格标题。我的标题能够毫无问题地对升序和降序进行排序。当我尝试在表格下方添加$this->Paginator->first、$this->Paginator->next、$this->Paginator->numbers 时,没有可见的分页器链接。我的数据库中现在有 6 个证据,我将分页器的限制设置为 3。这是我的代码:
EvidencesController.php
<?php
class EvidencesController extends AppController{
public $components = array('Session','Paginator');
var $helpers = array( 'Form','Paginator' );
public function index(){
$this->Paginator->setting = array(
'limit' => 3,
'order' => array(
'Evidence.title' => 'asc'
)
);
$data = $this->Paginator->paginate('Evidence');
$this->set('evidences',$data);
}
}
?>
index.ctp
<h1>Evidences</h1>
<?php echo $this->Html->link('Create a new Evidence', array('controller'=>'evidence','action'=>'add'))?>
<br>
<table>
<tr>
<th><?php echo $this->Paginator->sort('title'); ?></th>
<th><?php echo $this->Paginator->sort('date'); ?></th>
<th><?php echo $this->Paginator->sort('sourcetype'); ?></th>
<th><?php echo $this->Paginator->sort('user_id'); ?></th>
<th><?php echo $this->Paginator->sort('created'); ?></th>
<?php if(AuthComponent::user('type') == 1) : ?>
<th>Edit</th>
<th>Delete</th>
<?php endif; ?>
<th>Add</th>
</tr>
<?php
foreach($evidences as $evidence) :
?>
<tr>
<td><?php echo $this->Html->link($evidence['Evidence']['title'], array('controller' => 'evidences', 'action'=> 'view', $evidence['Evidence']['id'])); ?></td>
<td><?php echo $evidence['Evidence']['date']; ?></td>
<td><?php echo $evidence['Evidence']['sourcetype']; ?></td>
<td><?php echo $evidence['User']['username']; ?></td>
<td><?php echo $evidence['Evidence']['created']; ?></td>
</tr>
<?php
endforeach;
//unset($project);
?>
</table>
<?php
echo "<div class='paging'>";
echo $this->Paginator->first("First");
if($this->Paginator->hasPrev()){
echo $this->Paginator->prev("Prev");
}
echo $this->Paginator->numbers(array('modulus' => 2));
if($this->Paginator->hasNext()){
echo $this->Paginator->next("Next");
}
echo $this->Paginator->last("Last");
echo "</div>";
?>
如何使用 CakePHP 的 Paginator 添加第一个、最后一个、下一个、最后一个和数字计数?
任何帮助将不胜感激!
【问题讨论】:
标签: php cakephp pagination