0

我有一个表单,PhotoForm,它有一个嵌入的 BlobDataForm。

我可以很好地保存 blbo 数据,我的问题来了,使用 blob_data 表。

我有 2 个字段,image_width 和 image_height。

当 blob 被保存时,我也想保存这些详细信息。

我已经覆盖了 doSave();

  protected function doSave($con = null)
  {
    if (null === $con)
    {
      $con = $this->getConnection();
    }

    $this->updateObject();
    $blobData = new BlobData();
    $this->saveEmbeddedForms($con);
    $this->getObject()->setBlobData($this->getEmbeddedForm('blob_data')->getObject());
    $this->getObject()->save($con);
  }

我还需要覆盖 saveEmbeddedForms() 吗?

谢谢

编辑:

好的,所以看来我需要覆盖:

过程值()

我只是无法获取图像的宽度和高度属性。

有谁知道我会怎么做?

谢谢

4

2 回答 2

1

如果您可以从 blob_data 字段中获取这两个信息,则可以覆盖 BlobData 类的 preSave 方法,该方法在保存对象之前调用:

public function preSave($event)
{ 
     //get the information from the blob_data
     $this->image_width = ... ;
     $this->image_height = ... ;

}
于 2011-02-24T14:01:10.270 回答
0

是的,毕竟,我不得不重写 saveEmbeddedForms:

  public function saveEmbeddedForms($con = null, $forms = null)
  {
    if (null === $con)
    {
      $con = $this->getConnection();
    }

    if (null === $forms)
    {
       $photos = $this->getValue('blob_data');
       $forms = $this->embeddedForms;
       foreach ($this->embeddedForms['blob_data'] as $name => $form)
       {
            if (!isset($photos[$name]))
            {
              unset($forms['blob_data'][$name]);
            }
        }
    }

    foreach ($forms as $form)
    {
      if ($form instanceof sfFormObject)
      {
        $form->saveEmbeddedForms($con);
        $blobData = $form->getObject()->getBlobData();
         $imageStream = stream_get_contents($blobData);
         $image = imagecreatefromstring($imageStream);
         $form->getObject()->setImageWidth(imagesx($image));
         $form->getObject()->setImageHeight(imagesy($image));
         $form->getObject()->setFileExtension('jpg');
         //return parent::preSave($con);
        $form->getObject()->save($con);
      }
      else
      {
        $this->saveEmbeddedForms($con, $form->getEmbeddedForms());
      }
    }
}

这似乎对我有用

谢谢

于 2011-02-25T09:15:44.790 回答