Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3978838
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:05:47+00:00 2026-05-20T05:05:47+00:00

I have an admin module, that has a file input filed, where I’d like

  • 0

I have an admin module, that has a file input filed, where I’d like to upload a file.
I am looking to upload the file to the database as a blob, as this is what I am restricted to. I am aware this is bad practice, but I cannot add files to the filesystem.

I have the following schema:

press_photo:
  id:                                      ~
  blob_data_id:                            { type: INTEGER, required: true, foreignTable: blob_data, foreignReference: id, onDelete: cascade }
  name:                                    { type: VARCHAR, size: '100', required: true }
  created_at:                              ~
  updated_at:                              ~

blob_data:
  id:                                      ~
  blob_data:                               { type: BLOB, required: true }
  created_at:                              ~
  updated_at:                              ~

So far, I have a created all the widgets and schemas in the BlobForm.class.php and I have then tried to embed this form into my PressPhotoForm.class.php

$this->embedForm('blob_data', new BlobDataForm());

Now when I select the file and upload, it does seem to be added to the blob_data table, but in the press_photo table, blob_data_id is blank and there is no checkbox on the input widget to say there is an image.

Would someone be able to shed some light on how I can get the blob_data_id into the press_photo table on upload?

Thanks

EDIT:

Here are my forms:

class BlobDataForm extends BaseBlobDataForm
{
 public function configure()
 {
   parent::configure();
   $this->widgetSchema ['blob_data'] = new sfWidgetFormInputFileEditable ( array (
            'label' => '',
            'file_src' => $this->getObject()->getBlobData(),
            'edit_mode' => ! $this->isNew () && $this->getObject()->getBlobData(),
            'template' => '<div>%file%<br />%input%<br />%delete% %delete_label%</div>'
   ));

    $this->setWidget('blob_data_type_id', new sfWidgetFormPropelChoice(array('model' => 'BlobDataType')));
    //$this->widgetSchema['blob_data_id'] = new sfWidgetFormInputHidden();


    $this->validatorSchema['blob_data'] = new sfValidatorPass();
    $this->validatorSchema ['blob_data'] = new fdValidatorImageToDB(array(
        'required'=>false
    ));

    $this->validatorSchema['blob_data']->setOption('mime_types', array('image/jpg','image/jpeg','application/pdf','application/msword'));

    $this->widgetSchema->setNameFormat('article_files[%s]');

    $this->widgetSchema->setLabels(array(
           'blob_data_type_id'=>'File Type',
           'blob_data'=>'File'
    ));

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

unset(

  $this['file_extension'],
  //unsetting to hide the drop down select-list
  //$this['blob_data_type_id'],
  $this['image_width'],
  $this['image_height'],
  $this['filesize'],
  $this['created_at'],
  $this['updated_at']
);

}

class PressPhotoForm extends BasePressPhotoForm
{

public function configure()
{
    // Execute the configure of the parent
    parent::configure();

    // Configure
    $this->configureWidgets();
    $this->configureValidators();
    //$this->embedForm('blob_data', new BlobDataForm());

    unset($this['blob_data_id'],$this['created_at'], $this['url'], $this['updated_at'], $this['image_size']);
}

protected function configureWidgets()
{
    $this->widgetSchema['description'] = new sfWidgetFormTextareaTinyMCE(array(
          'width' => 550,
          'height' => 350,
          'config' => 'theme_advanced_disable: "anchor,image,cleanup,help"',
    ));
      $subForm = new sfForm();
      for ($i = 0; $i < 1; $i++)
      {
        $blobData = new BlobData();
        $blobData->BlobData = $this->getObject();

        $form = new BlobDataForm($blobData);
        $pressPhoto = new PressPhoto();
        $subForm->embedForm($i, $form);

        $this->getObject()->setBlobDataId($blobData->getId());
      }
      $this->embedForm('blob_data', $subForm);


    $this->widgetSchema->setLabels(array(
           'blob_data'=>'File'
    ));
}

protected function configureValidators()
{

    $this->validatorSchema['name']->setOption('required', true);
    $this->validatorSchema['name']->setMessage('required', 'You must provide a name');

    $this->validatorSchema['press_photo_category_id']->setOption('required', true);
    $this->validatorSchema['press_photo_category_id']->setMessage('required', 'You must select a category');

}

public function saveEmbeddedForm($con = null, $forms = null)
{
    $dataForms = $this->getEmbeddedForm('blob_data')->getEmbeddedForms();
    foreach ($dataForms as $dataForm)
    $dataForm->getObject()->setBlobDataId($this->getObject()->getId());
    parent::saveEmbeddedForm($con, $forms);
}

}

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T05:05:48+00:00Added an answer on May 20, 2026 at 5:05 am

    Ok, so my answer was i needed to override

    doSave()

    as the saveEmbeddedForms call is after the save() method.

    So I just swapped them around in my method:

      protected function doSave($con = null)
      {
        if (null === $con)
        {
          $con = $this->getConnection();
        }
    
        $this->updateObject();
        $blobData = new BlobData();
        //gets called first
        $this->saveEmbeddedForms($con);
        $this->getObject()->setBlobData($this->getEmbeddedForm('blob_data')->getObject());
        //object is saved after embedded form
        $this->getObject()->save($con);
      }
    

    Hope this helps someone

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.