Question

I have two tables and this is how the schema looks like:

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 }

I am currently using Symfony 1.4's (propel orm) admin but I can't successfully merge all these three forms into one.

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();
}

However I get this error:

500 | Internal Server Error | sfValidatorErrorSchema

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

I'm really stuck right now. I hope someone can point me to the right direction.

I just want to have these three forms merged into one single admin form.

Was it helpful?

Solution

The validatorErrorSchema is just an array of sfValidator objects that helps create an association with your form fields. Is that the entire error message?

Delete your code where you override the save() method. You should create the relationships between the Propel objects before you embed them in their corresponding forms like this:

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);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top