2011-02-24 3 views
0

저는 PhotoForm이라는 양식이 있습니다. PhotoForm에는 emebedded BlobDataForm이 있습니다.symfony - blob 데이터 이미지 크기 절약

blbo 데이터를 잘 저장할 수 있습니다. 내 문제는 blob_data 테이블에 있습니다.

2 개의 필드, image_width 및 image_height가 있습니다.

블롭을 저장할 때 이러한 세부 정보도 저장하고 싶습니다.

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()도 재정의해야합니까?

감사

편집 :

좋아, 내가 오버라이드 (override) 할 필요가 보인다 있도록 : 난 그냥 문제가 이미지 폭 얻는 데

processValues ​​()

을 및 높이 속성.

아무도 내가 어떻게하는지 알 수 있습니까?

감사

답변

0

오른쪽, 후 정도

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

날 위해 일하는 것 같았다 : 모든 것을, 나는 saveEmbeddedForms을 무시했다

감사합니다.

1

당신이 당신의 blob_data 필드에서이 두 정보를 얻을 수 있다면, 당신은 단지 저장하는 객체 전에 호출하여 BlobData 클래스의 프리 세이브 방법을 재정의 할 수

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

} 
+0

나를 도와 줄 수 있습니까? 폭과 높이의 값을 얻는 방법을 잘 모르겠습니다. 감사 – terrid25

관련 문제