我有两个表,这就是架构的样子:
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(推进式)管理员,但我无法成功将所有这三种形式合并为一种。
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();
我现在真的被困住了。我希望有人能指出我正确的方向。
我只想将这三种表单合并为一个管理表单。
答案 0 :(得分: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);
}