jii列到yii2中的gridview

时间:2016-04-04 04:05:12

标签: json gridview yii2

我有一张桌子: id |名字|值|

1 |约翰| {" data1":{" key1":" abs"," key2":" qwe"},&# 34; DATA2" {" KEY1":" ASD"" KEY2":"物镜"}}

在每一行中,json的长度不同。我需要创建gridView,如:

id |名字| abs | asd | ...

1 |约翰| qwe | obj | ...

我的代码SqlDataProvider:

#!/bin/bash

. ./tobeincluded1   #using the . to include a file
source ./tobeincluded2 #using the source command to include a file

echo "x : $x"
echo "y : $y"

和GridView:

$count = Yii::$app->db->createCommand('
            SELECT COUNT(id) FROM statistics', [':status' => 0])-     >queryScalar();
        $dataProvider = new SqlDataProvider([
            'sql' => 'SELECT id, name, value

                    FROM 
                    statistics',

            'totalCount' => $count,
            'key'        => 'id',
        ]);

    return $this->render('statistics',
    [   
        'dataProvider'      => $dataProvider,

    ]);

当我添加专栏' vlues'结果就像:

1 |约翰| {" data1":{" key1":" abs"," key2":" qwe"},&# 34; DATA2" {" KEY1":" ASD"" KEY2":"物镜"}}

请帮忙!

1 个答案:

答案 0 :(得分:0)

我认为您可以像这样添加值列

   'columns' => [
        'id',
        'name',
        [
           'attribute' => 'data1',
           'value' => function($model){
              return (json_decode($model->value)->data1);
        }
       ],
    ],