0

在我的数据库中有一个表,其中有一列文本类型。此列包含一个序列化数组。该数组由另一个应用程序读取和存储,我无法更改其格式。

序列化数组包含两种不同语言的数据库名称、表名称和列名称的选择。

我想在 Symfony2 中编写一个能够修改这个序列化数组的控制器、实体、表单等。

我可以使用一个脚本,它可以提供每个序列化数组可能包含的所有可能的数据库名称、表名和列名的数组。

目标是提供一个复选框列表,用户可以在其中选择数据库、表和列。接下来,他们可以对名称进行翻译。

由于所有数据都非常不稳定,我不确定这在 Symfony2 中是否可行。

另一种方法是制作以下实体:{数据库、表、列}并完全面向对象。然后我可以将序列化数组中的选择导出到期望它的外部应用程序......

你们能听懂我的推理吗?我是否忽略了这里的策略......?

补充:数组是一个嵌套数组,最多为五度。数据库包含表,其中包含列。每个项目都有一个原始名称和一个翻译名称。

4

2 回答 2

0

I know it's really late but I was really busy with university so I couldn't answer sooner

This is what I think is the best to do

Imagine that the table that contains the column which contains your array is called foo

So you make an entity which is called Foo and contains a field(type text) that has the name you like

Now the tricky part is to make an object called Database that contains all the relations you need(To a Table object and Table objects to column Objects)

So even though I told you to make the field type as text you will pas the object Database to this field

So how it's going to work

The Database object will have a __string method that will return the serialized array of the object the way you want

This way when doctrine2 tries to save the Database object in the text field it will be saved as the string that __string method returns

And you will have getDatabase that will converts the serialized array to the database object

This is the idea that I have and not sure if it suits you or not

于 2013-01-05T13:27:00.743 回答
0

我想你回答了你自己的猜测:

An alternative is to make the following entities: { database, table, column } and do it fully OO.
And then I could export a selection in a serialized array, to the external application that 
expects it that way...

您将从映射到您的表的主实体开始。

class SomeEntity
{
    protected $serializedInfo;

    public getDatabases()
    {
        // Process serializedInfo into an array of database objects and return

然后将 SomeEntity 传递给 SomeEntityFormType,后者又使用 DatabaseFormTypes 的集合。然后 DatabaseFormType 有一个 TableFormTypes 的集合等等。

最终您的表单将被发布并且 SomeEntity 将被更新。然后,您在发布之前进行序列化。应该直截了当。如果您希望用户添加信息,可能会更具挑战性,但即便如此,它也是可行的。

于 2012-12-18T17:18:32.910 回答