我正在使用sqldataprovider,我正在调用非对象错误的成员函数getCount()。我不知道我做错了什么。下面是我的控制器代码
public function actionTicketbookingreport()
{
$count = Yii::$app->db->createCommand('
SELECT COUNT(*) FROM screen_ticket_booking_history WHERE status=:status
', [':status' => 0])->queryScalar();
$dataProvider = new SqlDataProvider([
'sql' => 'SELECT A1.booking_id As Booking_id,
A1.booking_date As Booking_date,
A2.movie_name As Movie,
A3.theatre_name As Theatre,
A1.amount As Amount
FROM
screen_ticket_booking_history A1
LEFT OUTER JOIN movies A2 ON A1.movie_id=A2.id
LEFT OUTER JOIN theatres A3 ON A1.theatre_id=A3.id
LEFT OUTER JOIN users_backend A4 ON A3.users_backend_id=A4.id
WHERE A1.booking_date >= :start_date
AND A1.booking_date <= :end_date
AND A3.users_backend_id = :id',
'params' => [':start_date' => $year_start,':end_date'=>$year_end,':id'=> $userid],
'totalCount' => $count,
]);
// get the user records in the current page
$models = $dataProvider->getModels();
//no dataprovider
return $this->render('index',
[ 'model' => $model,
'dataProvider' => $models,
]);
}
答案 0 :(得分:1)
Okey我看到哪里出了什么问题
return $this->render('index',
[ 'model' => $model,
'dataProvider' => $models,
]);
getModels()只返回一个元素数组。如果您正在尝试生成gridView或类似的东西,您应该提供整个dataProvider。所以它应该是
'dataProvider' => $dataProvider,