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

    • 0
    • 4
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 130
    Comment on it

    In cakephp framework there is a way which features pagination easily on your web page.
    This can be done as :


    Controller Code :

    public $components = array('Paginator','Flash');
    
      public function index() {
    
    
    
           $this->paginate = array(
            'limit' => 5,
            'order' => array('id' => 'asc')
        );
    
    
        $pots = $this->paginate('Post');
    
    
        $this->set('Posts', $posts);
        $this->Post->recursive = 0;
        $this->set('posts', $this->Paginator->paginate());
    
        }
    

    In the controller we have defined the paginate component as public $components = array('Paginator','Flash');
    then we have included the conditions in the index function where we have limited the post to 5 with 'limit' => 5, and assigned in ascending order 'order' => array('id' => 'asc'), we can also make a condition which wont include a particular ID in post it can be done as by (conditions => array(User.id != => 6)).


    Index Code :


    In the index.ctp the data is presented. The presentation is done in table.
    $this->Paginator has many functions for paging. the code for the pagination is as :

      <?php
        echo $this->Paginator->counter(array(
        'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}')
        ));
        ?>  </p>
        <div class="paging">
        <?php
            echo $this->Paginator->prev('< ' . __('previous'), array(), null, array('class' => 'prev disabled'));
            echo $this->Paginator->numbers(array('separator' => ''));
            echo $this->Paginator->next(__('next') . ' >', array(), null, array('class' => 'next disabled'));
        ?>
        </div>
    

    In this way we can apply Pagination to limit the number of posts on the presentation page.

 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: