[CakePHP]: Technical guidelines pagination in CakePHP

CAKE PHP

Posted on 2015-12-10 11:08:16


Through the series before the Framework, you must now have the perspective relative working principle of CakePHP . Especially we have to learn about how it works on databases in CakePHP . In this article, we continue to learn about the technical paging CakePHP to complete applications more fully.

To make it easier to interact with the database (DB). First we need to configure the path app / config / database.php information connected to the system. (View Post for beginners ).
Once connected to the system, then we carried out the following queries to proceed with creating the data table form, to cater to the test code below.
Continue, Created Controller Books (app/controllers/books/books_controller.php)
- To use the CakePHP pagination functions are in the Controller required components paginator helper:
và namespace paginate : - Here I get all the data beginning with the first record in 4 order diminishes with "title". - If you just take the first required number of field:   - To get the data of the variable configuration namespace paginate we use the $ this-> paginate ('ten_model') , in this example, my model named Book.   - The configuration variables used namspace paginate function $ this-> paginate ('name_model')
Like the configuration of the conditions of data access and retrieve data by function $ this-> find ('...'); . ( See the database query function ) - We just need to configure so that can be divided page for a database, the default CakePHP page using variables to determine the current page.
Continue, created model Book (app/models/book.php)
Then we create a new view (the display) to the paging (app / views / books / paging.ctp)
Finally, we ran the following link to view the results:
http://localhost/cakephp/books/paging
You can see results same image: Paginating