我試圖表明使用的GridView從視圖數據庫中的數據,但我有問題Yii2:不能顯示的數據中的Widget的GridView
錯誤信息
未知方法 - 警予\基地\ UnknownMethodException 調用未知的方法:警予\ DB \ ActiveQuery :: getCount將()
我控制器
public function actionIndex()
{
$sql = "SELECT presensi.presensi_tanggal 'tanggal', sum(if(hadir.keteranganhadir_id='1',1,0)) 'hadir', sum(if(hadir.keteranganhadir_id='2',1,0)) 'tidak_hadir', count(*) 'total' FROM hadir, keteranganhadir, presensi where hadir.keteranganhadir_id = keteranganhadir.keteranganhadir_id and hadir.presensi_id = presensi.presensi_id group by presensi.presensi_tanggal";
$model = Hadir::findBySql($sql)->all();
return $this->render('index', [
'hadir' => $model,
]);
}
我看來
<?= GridView::widget([
'dataProvider' => $hadir,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'tanggal',
'hadir',
'tidak_hadir',
'total',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
我怎樣才能解決這個問題?
我該如何實現這個到我的sql? – ariyandi