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

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 278
    Comment on it

    In CakePHP pagination is provided by a Component defined in the controller for making paginated queries much easier. PaginatorHelper View is used for generating pagination links & buttons in a simpler way.

    Setting up the Query:

    Let us take a controller with name Posts,so the query will go as:

    class PostsController extends AppController {
    
    public $components = array('Paginator'); //Using Paginator Component
    
    public $paginate = array(
        'fields' => array('Post.id', 'Post.created'),
        'limit' => 25,
        'order' => array(
            'Post.title' => 'asc'
        )
    );
    }
    

    The pagination query uses $paginate controller variable by default.These conditions,acts as the basis of the pagination queries applied.

    //Function which uses Paginator

    public function_list(recipes) {
        $this->Paginator->settings = $this->paginate;
        // similar to findAll(), but fetches paged results
        $data = $this->Paginator->paginate('Recipe');
        $this->set('data', $data); 
    }
    

    One can set conditions and other pagination array settings inside your action.Enjoy guys!!!

 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: