0

我有两个表,这就是架构的样子:

customer:
id:
username: { type: varchar, size: 50, required: true }
password: { type: varchar, size: 50, required: true }
hash: { type: varchar, size: 50, required: true }

customer_profile:
id: { type: integer, foreignTable: customer, foreignReference: id, primaryKey: true, required: true, onDelete: cascade, onUpdate: cascade}
country: { type: varchar, size: 80, required: true }
state: { type: varchar, size: 80, required: true }
city: { type: varchar, size: 80, required: true }
zip: { type: varchar, size: 80, required: true }

customer_info:
id: { type: integer, foreignTable: customer, foreignReference: id, primaryKey: true, required: true, onDelete: cascade, onUpdate: cascade}
preference: { type: longvarchar }
likes: { type: longvarchar }

我目前正在使用 Symfony 1.4 的(propel orm)管理员,但我无法成功地将所有这三种形式合并为一个。

public function configure()
{
$use_fields = array(........);
$sub_form1   = new CustomerProfileForm($this->getObject()->getCustomerProfile());
$this->embedForm('profile', $sub_form1);
array_push($use_fields, 'profile');

$sub_form1->widgetSchema->setNameFormat('customer_profile[%s]');
$sub_form2   = new CustomerInfoForm($this->getObject()->getCustomerInfo());
$this->embedForm('info', $sub_form2);
array_push($use_fields, 'info');
$sub_form2->widgetSchema->setNameFormat('customer_info[%s]');
$this->useFields($use_fields);
}

public function save($conn = null){
if ($forms === NULL)
 {
 $forms = $this->getEmbeddedForms();
 }
$forms['profile']->getObject()->setId($this->getObject()->getId());
$forms['profile']->save();
$forms['info']->getObject()->setId($this->getObject()->getId());
$forms['info']->save();
$this->getObject()->save();
}

但是我收到此错误:

500 | Internal Server Error | sfValidatorErrorSchema

$this->widgetSchema->setNameFormat('customer_profile[%s]');
$this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
parent::setup();

我现在真的被困住了。我希望有人能指出我正确的方向。

我只想将这三个表单合并到一个管理表单中。

4

1 回答 1

0

validatorErrorSchema 只是一个 sfValidator 对象数组,有助于创建与表单字段的关联。这是整个错误信息吗?

删除覆盖 save() 方法的代码。在将 Propel 对象嵌入到相应的形式中之前,您应该创建它们之间的关系,如下所示:

public function configure()
{
    $use_fields = array(........);
    $profile = $this->getObject()->getCustomerProfile();
    // Do you assign profile objects if they don't exist?
    if (!$profile) {
        $profile = new CustomerProfile();
        $profile->setCustomer($this->getObject());
    }
    $profileForm = new CustomerProfileForm($profile);
    $this->embedForm('profile', $profileForm);
    array_push($use_fields, 'profile');


    $info = $this->getObject()->getCustomerInfo();
    // Do you assign info objects if they don't exist?
    if (!$info) {
        $info = new CustomerInfo();
        $info->setCustomer($this->getObject());
    }
    $infoForm = new CustomerInfoForm($info);
    $this->embedForm('info', $infoForm);
    array_push($use_fields, 'info');

    $this->useFields($use_fields);
}
于 2012-12-05T05:43:09.920 回答