I have been working with Symfony2 and doctrine2 recently and have realized a peculiar datatype called DC2Type:array that certain Symfony2 Roles get saved as. To me it just looks like a serialized PHP array where a signifies the total number of elements, i is the array index.
我最近一直在使用Symfony2和doctrine2,并且已经实现了一种特殊的数据类型,称为DC2Type:数组,某些Symfony2角色被保存为。对我来说,它看起来像一个序列化的PHP数组,其中a表示元素的总数,i是数组索引。
The value looks like this:
值如下所示:
a:15:{i:0;s:32:"ROLE_SONATA_USER_ADMIN_USER_EDIT";i:1;s:32:"ROLE_SONATA_USER_ADMIN_USER_LIST";i:2;s:34:"ROLE_SONATA_USER_ADMIN_USER_CREATE";i:3;s:32:"ROLE_SONATA_USER_ADMIN_USER_VIEW";i:4;s:34:"ROLE_SONATA_USER_ADMIN_USER_DELETE";i:5;s:36:"ROLE_SONATA_USER_ADMIN_USER_OPERATOR";i:6;s:34:"ROLE_SONATA_USER_ADMIN_USER_MASTER";i:7;s:33:"ROLE_SONATA_USER_ADMIN_GROUP_EDIT";i:8;s:33:"ROLE_SONATA_USER_ADMIN_GROUP_LIST";i:9;s:35:"ROLE_SONATA_USER_ADMIN_GROUP_CREATE";i:10;s:33:"ROLE_SONATA_USER_ADMIN_GROUP_VIEW";i:11;s:35:"ROLE_SONATA_USER_ADMIN_GROUP_DELETE";i:12;s:37:"ROLE_SONATA_USER_ADMIN_GROUP_OPERATOR";i:13;s:35:"ROLE_SONATA_USER_ADMIN_GROUP_MASTER";i:14;s:10:"ROLE_ADMIN";}
I want to know what this datatype is?
我想知道这个数据类型是什么?
And what do the following identifier signifies:
以下标识符表示什么:
s:
I have searched the internet but haven't got any useful data.
我搜索过互联网但没有得到任何有用的数据。
I also bumped upon this cookbook entry - http://readthedocs.org/docs/doctrine-orm/en/2.0.x/cookbook/mysql-enums.html but didn't figure out the origin.
我还碰到了这本食谱条目 - http://readthedocs.org/docs/doctrine-orm/en/2.0.x/cookbook/mysql-enums.html但是没有找出原点。
2 个解决方案
#1
26
This is not a data type. You might have noticed that the column type is LONGTEXT. DC2Type:array is a comment of the field.
这不是数据类型。您可能已经注意到列类型是LONGTEXT。 DC2Type:array是该字段的注释。
Doctrine uses the field's comment as column's metadata storage place. Since Mysql does not allow you to store an array, Doctrine use DC2Type:array as comment in order to know how to unserialize the content.
Doctrine使用字段的注释作为列的元数据存储位置。由于Mysql不允许您存储数组,因此Doctrine使用DC2Type:array作为注释,以便了解如何反序列化内容。
Take a look at the link below.
看看下面的链接。
https://github.com/doctrine/dbal/issues/1614
https://github.com/doctrine/dbal/issues/1614
From the link you mentioned, you can see that the comment DC2Type:enumvisibility indicates that the content of the field is a flag, indicating that the record is visible or not. It is not a new data type at all. It should be considered an helper strategy in the database level. For Doctrine, it's a custom data type.
从您提到的链接中,您可以看到注释DC2Type:enumvisibility指示该字段的内容是一个标志,表示该记录是否可见。它根本不是一种新的数据类型。它应该被视为数据库级别的帮助策略。对于Doctrine,它是一种自定义数据类型。
#2
9
This is simply a string. Its format is a serialized PHP array. The s: refers to the size or length of each item value in the array.
这只是一个字符串。它的格式是一个序列化的PHP数组。 s:指数组中每个项值的大小或长度。
e.g. s:32:"ROLE_SONATA_USER_ADMIN_USER_EDIT"
例如S:32: “ROLE_SONATA_USER_ADMIN_USER_EDIT”
If you count the characters in the ROLE string, there are 32.
如果计算ROLE字符串中的字符数,则为32。
Hope this helps.
希望这可以帮助。
#1
26
This is not a data type. You might have noticed that the column type is LONGTEXT. DC2Type:array is a comment of the field.
这不是数据类型。您可能已经注意到列类型是LONGTEXT。 DC2Type:array是该字段的注释。
Doctrine uses the field's comment as column's metadata storage place. Since Mysql does not allow you to store an array, Doctrine use DC2Type:array as comment in order to know how to unserialize the content.
Doctrine使用字段的注释作为列的元数据存储位置。由于Mysql不允许您存储数组,因此Doctrine使用DC2Type:array作为注释,以便了解如何反序列化内容。
Take a look at the link below.
看看下面的链接。
https://github.com/doctrine/dbal/issues/1614
https://github.com/doctrine/dbal/issues/1614
From the link you mentioned, you can see that the comment DC2Type:enumvisibility indicates that the content of the field is a flag, indicating that the record is visible or not. It is not a new data type at all. It should be considered an helper strategy in the database level. For Doctrine, it's a custom data type.
从您提到的链接中,您可以看到注释DC2Type:enumvisibility指示该字段的内容是一个标志,表示该记录是否可见。它根本不是一种新的数据类型。它应该被视为数据库级别的帮助策略。对于Doctrine,它是一种自定义数据类型。
#2
9
This is simply a string. Its format is a serialized PHP array. The s: refers to the size or length of each item value in the array.
这只是一个字符串。它的格式是一个序列化的PHP数组。 s:指数组中每个项值的大小或长度。
e.g. s:32:"ROLE_SONATA_USER_ADMIN_USER_EDIT"
例如S:32: “ROLE_SONATA_USER_ADMIN_USER_EDIT”
If you count the characters in the ROLE string, there are 32.
如果计算ROLE字符串中的字符数,则为32。
Hope this helps.
希望这可以帮助。