dimanche 1 février 2015

How to add Pagination numbers, next, previous with CakePHP


Vote count:

0




I am using Cakephp 2.x to try and paginate one of my Model's index. I have successfully used the Paginator to create my table heading. My headings are able to sort Ascending and Descending without a problem. When I try to add $this->Paginator->first, $this->Paginator->next, $this->Paginator->numbers below the table there are no Paginator links visible. There are 6 evidences in my database right now, and I have the limit of the paginator set to 3. Here is my code:


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>";
?>


How do I add first, last, next, last and number count with CakePHP's Paginator?


Any help would be greatly appreciated!



asked 22 secs ago







How to add Pagination numbers, next, previous with CakePHP

Aucun commentaire:

Enregistrer un commentaire