Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Limit the number of records to be displayed in cakephp

    • 0
    • 2
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 495
    Comment on it

    Showing a limited number of records per page has been a basic part of each application and it is very difficult task to bring out. CakePHP provides a easy way for limiting record to be display or for paginate data.

    The PaginatorHelper gives us a easy and  great solution for pagination data. Aside from pagination, it also have simple to use sorting highlights.

    For implementing pagination we have to put below simple code into our controller.

    public $paginate = [
    'limit' => 5, // by this only 5 number of records should be display in a single page.
    'order' => [
    'Users.id' => 'asc'
    ]
    ];
    

    Then we have to put below code in that function where we  want to  display data.

    public function detail() {
                
    
                $result=$this->paginate('User');
         
               $this->set('registers',$result);
        
            }
    

    Then we have to add following code in our view.

    <?php echo $this->Paginator->numbers(); ?>    
        <?php echo $this->Paginator->prev(' Previous', null, null, array('class' => 'disabled')); ?>
        <?php echo $this->Paginator->next('Next ', null, null, array('class' => 'disabled')); ?>    
        <?php echo $this->Paginator->counter(); ?>
    

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: