我正在使用yii \ db \ Command和SqlDataProvider来填充GridView小部件网格。 SqlDataProvider正在运行,但是GridView小部件需要结果集的计数来计算网格分页。计数来自yii \ db \ Command,它不起作用。有人能看到解决方案吗?
public function actionIndex()
{
$searchModel = new postcodeSearch();
//$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$pc = "CB7 5UE";
$count = Yii::$app->db->createCommand('SELECT COUNT(*) FROM
geodata.codepoint_bng as p, geodata.river_waterbody_catchments_cycle1 as w
FULL OUTER JOIN geodata.wap_costs as c ON w.ea_wb_id = c.wbid
FULL OUTER JOIN geodata.actypes as t ON c.actype = t.actiontype
INNER JOIN geodata.river_ecological_status_2013 as wb_ec ON w.ea_wb_id = wb_ec.wb_id
WHERE
ST_Intersects(p.geom, w.geom) AND p.postcode = $pc');
//$count = 20;
$dataProvider = new SqlDataProvider([
'sql' => "SELECT
w.name,
w.ea_wb_id,
wb_ec.ecostatus,
wb_ec.ecocert,
t.actgroup,
t.actdesc,
c.anncost,
c.initcost,
c.comment
FROM
geodata.codepoint_bng as p, geodata.river_waterbody_catchments_cycle1 as w
FULL OUTER JOIN geodata.wap_costs as c ON w.ea_wb_id = c.wbid
FULL OUTER JOIN geodata.actypes as t ON c.actype = t.actiontype
INNER JOIN geodata.river_ecological_status_2013 as wb_ec ON w.ea_wb_id = wb_ec.wb_id
WHERE
ST_Intersects(p.geom, w.geom) AND p.postcode = '$pc'",
'totalCount' => $count,
'sort' => [
'attributes' => [
'ea_wb_id',
],
],
'pagination' => [
'pageSize' => 20,
],
]);
答案 0 :(得分:0)
引号('
- > "
)出现错误,您的计数查询必须先执行。
$count = Yii::$app->db->createCommand("SELECT COUNT(*) FROM
geodata.codepoint_bng as p, geodata.river_waterbody_catchments_cycle1 as w
FULL OUTER JOIN geodata.wap_costs as c ON w.ea_wb_id = c.wbid
FULL OUTER JOIN geodata.actypes as t ON c.actype = t.actiontype
INNER JOIN geodata.river_ecological_status_2013 as wb_ec ON w.ea_wb_id = wb_ec.wb_id
WHERE
ST_Intersects(p.geom, w.geom) AND p.postcode = '$pc'")->queryScalar();