开发者

embedForm saving problem - Symfony

I have schema like:

Schema:

 article:
   id:                                      ~
   title:                                   { type: VARCHAR, size: '255', required: true }
   created_at:                              { type: TIMESTAMP, required: true }
   updated_at:                              { type: TIMESTAMP, required: true }

 article_data:
   id:                                      ~
   article_data:                            { type: BLOB, required: true } 
   article_filename:                        { type: VARCHAR, size: '255'}
   article_id:                              { type: INTEGER, required: true, foreignTable: article, foreignReference: id, onDelete: cascade }

So, in my article admin module, I'd like to disp开发者_StackOverflow中文版lay the article_data widget, which is a file upload.

Everything is fine. But when saving the uploaded file to the server, the article_id field is null.

Is there a way i could get the id of the article and save it as the article_id of the article_data table?

Thanks

EDIT:

I think I need to override the saveEmbeddedForm() method, but I am not sure what I'd need to do.

Could someone help with some code for a saveEmbeddedForm()?

Thanks


I don't known Propel, but in Doctrine you could do something like this:

class ArticleForm extends BaseForm
{
  public function configure()
  {
    parent::configure();

    $form  = new sfForm();
    $datas = $this->getObject()->getDatas();

    foreach ($datas as $index => $data)
      $form->embedForm($index, new ArticleDataForm($data));

    $this->embedForm('dataForms', $form);
  }

  public function saveEmbeddedForm($con = null, $forms = null)
  {
    $dataForms = $this->getEmbeddedForm('dataForms')->getEmbeddedForms();

    foreach ($dataForms as $dataForm)
      $dataForm->getObject()->setArticle($this->getObject());

    parent::saveEmbeddedForm($con, $forms);
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜