yii2:带有分页和 searcModel 的 SqlDataProvider 出现错误 preg_match() 期望参数 2 为字符串,给定的对象

yii2: SqlDataProvider with pagination and searcModel getting error preg_match() expects parameter 2 to be string, object given

我想使用 sqlDataProvider 将来自不同 table 的数据显示到 gridview 并计算它,这里是我在 siteController.php
中的代码 public function actionSyahriyah() { $searchModel = new SyahriyahSearch(); $db = Yii::$app->db; $bayar = $db ->createCommand('SELECT sy.no_syahriyah, sy.banyak, sa.nama, sy.tgl, sa.tarif FROM santri sa, syahriyah sy WHERE sa.no_induk = sy.no_induk ORDER BY sy.tgl'); $dataProvider = new SqlDataProvider([ 'sql' => $bayar, 'pagination' => [ 'pageSize' => 5 ], ]); return $this->render('syahriyah',[ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); }
这是网格视图:
<?= GridView::widget([ 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [ // ['class' => 'yii\grid\SerialColumn'], 'tgl', 'banyak', ], 'export' => false, ]); ?>

您可以使用 dataProvider

<?php

    $bayar = $db ->createCommand('SELECT sy.no_syahriyah, sy.banyak, sa.nama, sy.tgl, sa.tarif 
           FROM santri sa, syahriyah sy 
           WHERE sa.no_induk = sy.no_induk
           ORDER BY sy.tgl');

    $dataProvider = new SqlDataProvider([
        'sql' => $bayar,
        'pagination' => [
            'pageSize' => 5 
            ],
        ],
    ]);

?>