如何将 yii\db\Command 与 postgis st_intersects 查询一起使用?
How to use yii\db\Command with postgis st_intersects query?
我正在使用 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,
],
]);
引号错误('
->"
),您的计数查询必须先执行。
$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();
我正在使用 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,
],
]);
引号错误('
->"
),您的计数查询必须先执行。
$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();