From ad83952197315072124027bf39263eabc1979e1a Mon Sep 17 00:00:00 2001 From: Nisuga Jayawardana <44756803+NisugaJ@users.noreply.github.com> Date: Fri, 10 Jan 2020 14:48:18 +0530 Subject: [PATCH] Improved explanation in start-database.md (#17748) [skip ci] --- docs/guide/start-databases.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/guide/start-databases.md b/docs/guide/start-databases.md index e2e0cadd69..111f79e819 100644 --- a/docs/guide/start-databases.md +++ b/docs/guide/start-databases.md @@ -178,16 +178,19 @@ class CountryController extends Controller Save the above code in the file `controllers/CountryController.php`. -The `index` action calls `Country::find()`. This Active Record method builds a DB query that can be used to retrieve all of the data from the `country` table. -To limit the number of countries returned in each request, the query is paginated with the help of a +First, The `index` action calls `Country::find()`. This [find()](https://www.yiiframework.com/doc/api/2.0/yii-db-activerecord#find()-detail) method creates a [ActiveQuery](https://www.yiiframework.com/doc/api/2.0/yii-db-activequery) query object, which provides methods to access data from the `country` table. + +To limit the number of countries returned in each request, the query object is paginated with the help of a [[yii\data\Pagination]] object. The `Pagination` object serves two purposes: -* Sets the `offset` and `limit` clauses for the SQL statement represented by the query so that it only +* Sets the `offset` and `limit` clauses for the SQL statement represented by the query object so that it only returns a single page of data at a time (at most 5 rows in a page). * It's used in the view to display a pager consisting of a list of page buttons, as will be explained in the next subsection. + +Next, [all()](https://www.yiiframework.com/doc/api/2.0/yii-db-activequery#all()-detail) returns all `country` records based on the query results. -At the end of the code, the `index` action renders a view named `index`, and passes the country data as well as the pagination +At the end of the code, the `index` action renders a view named `index`, and passes the returned country data as well as the pagination information to it.