1. 程式人生 > >yii ActiveRecord 輸出執行sql語句

yii ActiveRecord 輸出執行sql語句

程式碼如下

<?php

namespace app\controllers;

use Yii;
use yii\web\Controller;
use yii\models;
use \app\models\Users;

class UserController extends \yii\web\Controller
{
    public function actionIndex(){
        $user= new Users;

        $data=$user::find()->joinWith("userGroup")->asArray()->all();
        echo $user::find()->joinWith("userGroup")
				        ->createCommand()
				        ->getRawSql();
        echo "<pre>";
        print_r($data);
    }
    

}