Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json 字段数据迁移写入有问题 #8

Open
jianyan74 opened this issue Jul 19, 2019 · 0 comments
Open

Json 字段数据迁移写入有问题 #8

jianyan74 opened this issue Jul 19, 2019 · 0 comments

Comments

@jianyan74
Copy link

        Yii::$app->db->createCommand()->insert('{{%sys_menu}}',
            [
                'id' => '1111',
                'title' => '会员管理',
                'cate_id' => '1',
                'pid' => '0',
                'url' => 'indexMember',
                'icon' => 'fa-user',
                'level' => '1',
                'dev' => '0',
                'sort' => '0',
                'params' => '[]',
                'status' => '1',
                'tree' => 'tr_0',
                'created_at' => '1553833327',
                'updated_at' => '1563167436'
            ])->execute();

比如我这一段 params是一个json字段,直接插入进去,表里面会显示 "[]"而不是[],用拿出来解析其实是无法解析的,我看了下yii2的源码,yii\db\mysql\JsonExpression 的 44 行代码 $params[$placeholder] = Json::encode($value); 实际上yii2对json数据入库之前是进行了编码的,所以生成数据迁移的时候是否变成数组?例如

    Yii::$app->db->createCommand()->insert('{{%sys_menu}}',
        [
            'id' => '1111',
            'title' => '会员管理',
            'cate_id' => '1',
            'pid' => '0',
            'url' => 'indexMember',
            'icon' => 'fa-user',
            'level' => '1',
            'dev' => '0',
            'sort' => '0',
            'params' => json_decode('[]'),
            'status' => '1',
            'tree' => 'tr_0',
            'created_at' => '1553833327',
            'updated_at' => '1563167436'
        ])->execute();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant