限时 5折! 详情
yii框架中searchmodel select查询COUNT(*) 完了GridView怎么读取
2 127 2017-09-13

searchModel中关联表之后group by 查询各总数:

$query = PromotionAudit::find();
$query->joinWith(['tProductArt', 'tProductPlus', 'tPromotionAuditLog','tReviewer']);
$query->select("tbl_art_report.product_id,COUNT(*) as count");

前台使用GridView::widget:

[
                'label' => '投诉数量',
                'value' => function ($model) {
                    $result = 0;
                    var_dump($model->count);exit;->读取不到 提示错误,这个model没有count字段
                    if (isset($model->count)) {
                        $result = $model->count;
                    }
                    return $result;
                },
            ],

那么问题来了,该怎么在前天读取这个count值啊0.0

  • 2 个回答
  • 需要明确一下这个值(count(*) as count)的结果表示的是什么?

  • 是想获取group by id后每个id的数量->问题已经解决啦,在modal开头定义public $count就行了!

登录 去赚佣金