Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Implementing Pagination in CakePHP

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 234
    Comment on it

    Pagination:

    It is used to limit the number of records to be displayed in a page. In cakephp we can easily implement pagination. We can use pagination by putting the following code in controller:

    public $paginate = [
            
            'limit' => 3,  //restricting the number of records to be displayed in a page
            'order' => [
                'Users.id' => 'asc'
            ]
        ];

    And we have to put the following code in that function where we will display data.

    public function detail() {
    			 
    			// $det = $this->User->find('all',array('fields'=>array('User.id','User.name','User.phone','User.email','User.pic')));
    			$det=$this->paginate('User');
    	        //set products data and pass to the view 
    	        $this->set('registers',$det);
    	       
    
    		}

    And put the following links in 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: