2012-11-30 46 views
0

我有兩個表,這是架構的樣子:symfony的1.4推進節約embedForm一個一對一的關係

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的(推動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(); 

我真的堅持現在。我希望有人能指出我正確的方向。

我只想把這三種形式合併成一個單一的管理形式。

+0

anybody? :(我仍然堅持這一點,只有保存的部分是什麼讓我瘋狂...覆蓋saveEmbeddedForm產生相同的錯誤,我真的不知道validatorErrorSchema是從哪裏來的 – kevin

回答

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); 
} 
+0

安東尼!非常感謝你!這正是我所需要的!我不知道這是解決問題的唯一方法。真的非常感謝! – kevin