Book Image

CakePHP Application Development

By : Ahsanul Bari, Anupom Syam
Book Image

CakePHP Application Development

By: Ahsanul Bari, Anupom Syam

Overview of this book

<p>Cake is a rapid development framework for PHP that uses well-known design patterns and provides a structured framework that enables PHP users at all levels to rapidly develop robust web applications, without any loss of flexibility. It means you can code faster, your code is better, and it makes writing Web 2.0-style apps a snap.<br /><br />This book offers step-by-step instructions to learn the CakePHP framework and to quickly develop and deploy web-based applications. It introduces the MVC pattern and coding styles using practical examples. It takes the developer through setting up a CakePHP development and deployment environment, and develops an example application to illustrate all of the techniques you need to write a complete, non-trivial application in PHP. It aims to assist PHP programmers to rapidly develop and deploy well-crafted and robust web-based applications with CakePHP.</p>
Table of Contents (18 chapters)
CakePHP Application Development
Credits
About the Authors
About the Reviewer
Preface
Index

Adding Pagination


As we already know, the homepage of Quickwall shows all the questions that have been posted. This is a good thing, but what will happen when there will be many more questions? All the questions will be shown in the page, and as a result the page might be a big one! Also, it is not a good idea in terms of performance. One solution may be user paginations—so that all the questions are not shown together in a page, but divided into many pages.

Implementing pagination using CakePHP can be ridiculously easy. It is a default functionality in version 1.2.

Time for Action

  1. In the Questions controller, add the following variable:

    <?php
    class QuestionsController extends AppController {
    var $name = 'Questions';
    var $paginate = array('limit' => 5, 'page' => 1, 'order' => array('Question.created'=>'desc'));
    ...
    }
    ?>
    
  2. In the home action of the Questions controller, change the following line:

    <?php
    class QuestionsController extends AppController {
    ...
    function home() {
    if...