2011-02-24 118 views
0

我有一個窗體,PhotoForm,它有一個嵌入的BlobDataForm。symfony - 保存blob數據圖像大小

我可以保存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()嗎?

感謝

編輯:

好了,看來我需要重寫:

processValues()

我只是遇到麻煩圖像寬度和高度屬性。

有誰知道我該怎麼做?

感謝

回答

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

這似乎爲我

工作

謝謝

1

如果你可以從你的blob_data領域得到這個2點的信息,您可以覆蓋你的BlobData類的preSave方法,只是保存對象之前稱爲:

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

} 
+0

你能否給我提供一些進一步的幫助?我不知道如何獲得寬度和高度的值。謝謝 – terrid25 2011-02-24 15:24:00