yii 输出当前的sql语句

<?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,
        ]);
    }
}
上一篇:UOJ #35. 后缀排序[后缀数组详细整理]


下一篇:2018.11.24 poj3415Common Substrings(后缀数组+单调栈)