【问题标题】:symfony1 enums with column aggregation inheritence具有列聚合继承的 symfony 1 枚举
【发布时间】:2013-06-25 11:40:02
【问题描述】:

我有一个配置文件表,用于保存所有用户的所有配置文件。 我有不同类型的用户,并希望每种类型的用户都有不同的选择选项来选择某个字段。
因此,两种用户类型都可以选择他们想要注册的时间,但有不同的选择 - 一种可以选择 2 年,另一种则不能。
schema.yml 看起来像这样:

用户资料:

columns:
    username:
        type: string(255)
        notnull: true
        unique: false

WriterUserProfile:

inheritance:
    type: column_aggregation
    extends: UserProfile
columns:
    register_time:
        type: enum
        values:
            - 6 months
            - 1 year
            - 2 years
            - Other
        default: other

ReaderUserProfile:

inheritance:
    type: column_aggregation
    extends: UserProfile
columns:
    register_time:
        type: enum
        values:
            - 6 months
            - 1 year
            - Other
        default: other

由于某种原因,我无法选择“2 年”选项 - 表单出现“无效”错误。
'2 年' 和 'Other' 是否因为它们都是第 3 选项而彼此重合?

【问题讨论】:

  • 不应该默认为“其他”而不是“其他”吗?
  • 也许可以,但这似乎有效。我的问题是“2 年”不起作用。

标签: doctrine symfony-1.4


【解决方案1】:

还有其他不常见的领域吗?这一个字段仅不足以导致使用列聚合。无论如何,如果同一个字段出现在多个子类中,则该字段应该向上移动,并且字段名称在所有相关类中应该是唯一的(在您的情况下为 UserProfile、WriterUserProfile、ReaderUserProfile)。

您可以在表单中更改选择字段的选项:

$choices = array('0' => 'a', '1' => 'b');
$this->getWidget('register_time')->setOption('choices', $choices);
$this->getValidator('register_time')->setOption('choices', array_keys($choices));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-19
    • 1970-01-01
    相关资源
    最近更新 更多