扩展成员类仍在尝试写入成员表

时间:2015-07-10 02:46:00

标签: silverstripe

我正在扩展成员表以包含基本地址详细信息。

设定:

class ClientMember extends Member {

    private static $db = array(
        "AddressLine1" => "Varchar(255)",
        "AddressLine2" => "Varchar(255)",
        "Country"      => "Varchar(50)",
        "State"        => "Varchar(50)",
        "Postcode"     => "Int(4)"
    );

    public function getCMSFields() {
        $fields = parent::getCMSFields();

        $addressLine1 = new TextField('AddressLine1', 'Address line 1', null, 255);
        $addressLine2 = new TextField('AddressLine2', 'Address line 2', null, 255);
        $country      = new CountryDropdownField('Country', 'Country', null, 'AU');
        $state        = new DropdownField('State', 'State', array('vic' => 'Victoria', 'sa' => 'South Australia', 'wa' => 'Western Australia'));
        $postcode     = new NumericField('Postcode', 'Postcode', null, 4);

        $fields->addFieldsToTab(
            'Root.Address',
            array(
                $addressLine1,
                $addressLine2,
                $country,
                $state,
                $postcode
            )
        );

        return $fields;
    }
}

我告诉SilverStripe在YAML配置中使用新的ClientMember类名称。

Injector:
  Member:
    class: ClientMember

问题:

然后我可以创建新的'客户成员'通过CMS和新的地址选项卡和字段都按预期工作。当我保存时,我收到以下错误:

  

string'无法运行查询:UPDATE"会员" SET" AddressLine1" =   '测试',"地址线2" ='测试',"国家" =' AU',"状态" =' vic',   "邮编" = 1212," LastEdited" =' 2015-07-10 12:43:58'在哪里" ID" =   10

     

未知列' AddressLine1'在'字段列表'' (长度= 245)

请注意,它正在尝试将新字段写入Member表而不是扩展的ClientMember表。

我错过了什么?

1 个答案:

答案 0 :(得分:4)

我这样做的方法是将Member扩展为DataExtension,如下所示:

ClientMember

class ClientMember extends DataExtension {

    private static $db = array(
        "AddressLine1" => "Varchar(255)",
        "AddressLine2" => "Varchar(255)",
        "Country"      => "Varchar(50)",
        "State"        => "Varchar(50)",
        "Postcode"     => "Int(4)"
    );

    public function updateCMSFields(FieldList $fields) {

        $addressLine1 = TextField::create('AddressLine1', 'Address line 1', null, 255);
        $addressLine2 = TextField::create('AddressLine2', 'Address line 2', null, 255);
        $country      = CountryDropdownField::create('Country', 'Country', null, 'AU');
        $state        = DropdownField::create('State', 'State', array('vic' => 'Victoria', 'sa' => 'South Australia', 'wa' => 'Western Australia'));
        $postcode     = NumericField::create('Postcode', 'Postcode', null, 4);

        $fields->addFieldsToTab(
            'Root.Address',
            array(
                $addressLine1,
                $addressLine2,
                $country,
                $state,
                $postcode
            )
        );
    }
}

config.yml

Member:
  extensions:
    - ClientMember