Symfony1 嵌入式BaseFormDoctrine表单的帮助

Symfony1 嵌入式BaseFormDoctrine表单的帮助,symfony1,doctrine,Symfony1,Doctrine,我有以下代码块: class MerchantStoreForm extends sfForm { public function configure() { $this->disableCSRFProtection(); $this->setWidgets(array( 'brand_id' => new sfWidgetFormDoctrineChoice(array('label'=> 'Store Brand','mo

我有以下代码块:

class MerchantStoreForm extends sfForm
{
  public function configure()
  {
    $this->disableCSRFProtection();

    $this->setWidgets(array(
          'brand_id' => new sfWidgetFormDoctrineChoice(array('label'=> 'Store Brand','model'=>'Brand','add_empty'=>'-Select Brand-','method'=>'getName','key_method'=>'getId','order_by'=>array('name','asc'))),
          'newbrand'    => new sfWidgetFormInputCheckbox(array('label' => 'New'),array('value'=>'Y'))
    ));

    $this->setValidators(array(
        'newbrand' => new sfValidatorString(array('required'=>false)),          
        'brand_id'  => new sfValidatorDoctrineChoice(array('model'=>'Brand'))
    ));

     $brand = new Brand();
    $brand_form = new BrandForm();
    $brand_form->widgetSchema['name']->setAttribute('style','display:none');
    $this->embedForm('brand', $brand_form);

    $this->getWidgetSchema()->setNameFormat('store[%s]');
  }

  public function execute()
  { 
   $form_values = $this->getValues();

    if($form_values['newbrand'])
    {
        $brand_form = $this->getEmbeddedForm('brand');
        $brand_form->save();
        $brand = $brand_form->getObject();
    }
    else
    {
        $brand = doctrine::getTable('Brand')->findOneById($form_values['brand_id']);
    }

    return $brand->getId();
  }
}
两个问题:

1) $brand_form->save()的魔力对我来说不起作用。我在symfony生成的BaseBrandForm.class.php中得到一个指向以下代码段的500内部服务器错误sfValidatorErrorSchema错误:

...
$this->widgetSchema->setNameFormat('brand[%s]');
$this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
...
但是,这可以替代:

        $brand_form->updateObject($form_values['brand']);
        $brand_form->getObject()->save();
为什么会这样

2) 为什么在对BaseFormDoctrine嵌入表单的对象调用getter方法时出现未定义的方法错误: 返回$brand->getId()

提前感谢你的帮助

Sharmil1)BrandForm抛出异常,因为它没有任何值。扩展了
sfFormObject
的类在直接嵌入到非对象表单(如
sfForm
)中时效果不佳

MerchantStoreForm在做什么?根据情况,它可能应该扩展
sfFormObject
,或者BrandForm应该是顶级表单。如果这是不可能的,您将不得不向MerchantStoreForm添加一个save方法,该方法调用
updateObject
save
。为了更好地理解正在发生的事情,请仔细阅读发生在
sfFormObject
中的逻辑-特别是如果您使用的是嵌入式表单,这是值得了解的

2) 这里没有线索。我想看看$brand实际上是什么。如果它是一个记录,并且该记录有一个id字段,那么没有理由不起作用