【问题标题】:How to use yii\db\Command with postgis st_intersects query?如何使用 yii\db\Command 和 postgis st_intersects 查询?
【发布时间】:2015-07-31 12:49:33
【问题描述】:

我正在使用 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,
    ],

]);

【问题讨论】:

  • 它不起作用是什么意思?你有 20 条记录,你的分页是 20 限制。所以它应该只有 1 页?

标签: gridview yii yii2


【解决方案1】:

引号有误('->"),必须先执行计数查询。

$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();

【讨论】:

    猜你喜欢
    • 2015-09-17
    • 2013-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多