Paginator Helper in CakePHP

Posted by Sachin Joshi
3
Jul 10, 2015
321 Views
Image Cake php provide inbuilt pagination we can use this by using Paginator Helper.

To use pagination first we need to use Paginator Component public $components = array('Paginator','Auth'); now add the below code in your controller here i am using pagination for users table
 
 
public function index() {
 $this->User->recursive = 0;
        $this->set('users', $this->Paginator->paginate());
    }
 

Now in your view add below code

<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<th><?php echo $this->Paginator->sort('id'); ?></th>
<th><?php echo $this->Paginator->sort('username'); ?></th>
<th><?php echo $this->Paginator->sort('password'); ?></th>
<th><?php echo $this->Paginator->sort('group_id'); ?></th>
<th><?php echo $this->Paginator->sort('created'); ?></th>
<th><?php echo $this->Paginator->sort('modified'); ?></th>
<th class="actions"><?php echo __('Actions'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($users as $user): ?>
<tr>
  • <table cellpadding="0" cellspacing="0">
  • <thead>
  • <tr>
  • <th><?php echo $this->Paginator->sort('id'); ?></th>
  • <th><?php echo $this->Paginator->sort('username'); ?></th>
  • <th><?php echo $this->Paginator->sort('password'); ?></th>
  • <th><?php echo $this->Paginator->sort('group_id'); ?></th>
  • <th><?php echo $this->Paginator->sort('created'); ?></th>
  • <th><?php echo $this->Paginator->sort('modified'); ?></th>
  • <th class="actions"><?php echo __('Actions'); ?></th>
  • </tr>
  • </thead>
  • <tbody>
  • <?php foreach ($users as $user): ?>
  • <tr>
  • - See more at: http://findnerd.com/list/view/PaginatorHelper-in-CakePHP/3351#sthash.UoubSws0.dpuf

  • <table cellpadding="0" cellspacing="0">
  • <thead>
  • <tr>
  • <th><?php echo $this->Paginator->sort('id'); ?></th>
  • <th><?php echo $this->Paginator->sort('username'); ?></th>
  • <th><?php echo $this->Paginator->sort('password'); ?></th>
  • <th><?php echo $this->Paginator->sort('group_id'); ?></th>
  • <th><?php echo $this->Paginator->sort('created'); ?></th>
  • <th><?php echo $this->Paginator->sort('modified'); ?></th>
  • <th class="actions"><?php echo __('Actions'); ?></th>
  • </tr>
  • </thead>
  • <tbody>
  • <?php foreach ($users as $user): ?>
  • <tr>
  • - See more at: http://findnerd.com/list/view/PaginatorHelper-in-CakePHP/3351#sthash.UoubSws0.dpuf

     
    - See full Blog at: Paginator Helper in CakePHP
     
    FindNerd is the right place to resolve PHP language problems. Here you can post PHP Questions and Answers.

    If you have any query on PHP language, Post it at FindNerd’sPHP Developer Forum.
    Comments
    avatar
    Please sign in to add comment.