<?php
namespace app\controllers;
use yii\web\Controller;
use yii\data\Pagination;
use app\models\Country;
class CountryController extends Controller{
public function actionIndex(){
$query = Country::find();
$pagination = new Pagination([
'defaultPageSize' => 7,
'totalCount' => $query->count(),
]);
$countries = $query->orderBy('name')
->offset($pagination->offset)
->limit($pagination->limit)
->all();
$commandQuery = clone $query;
echo $commandQuery->createCommand()->getRawSql();//SELECT * FROM `country` ORDER BY `name` LIMIT 7
return $this->render('index', [
'countries' => $countries,
'pagination' => $pagination,
]);
}
}