3

I'm using Symfony 1.4.4 and Doctrine and I need to upload an image on the server.

I've done that hundreds of times without any problem but this time something weird happens : instead of the filename being stored in the database, I find the string "Array".

Here's what I'm doing:

In my Form:

$this->useFields(array('filename'));
$this->embedI18n(sfConfig::get('app_cultures'));

$this->widgetSchema['filename'] = new sfWidgetFormInputFileEditable(array(
      'file_src'  => '/uploads/flash/'.$this->getObject()->getFilename(),
      'is_image'  => true,
      'edit_mode' => !$this->isNew(),
      'template'  => '<div id="">%file%</div><div id=""><h3 class="">change picture</h3>%input%</div>',
    ));

    $this->setValidator['filename'] = new sfValidatorFile(array(
      'mime_types' => 'web_images',
      'path' => sfConfig::get('sf_upload_dir').'/flash',
    ));

In my action:

public function executeIndex( sfWebRequest $request )
    {
        $this->flashContents = $this->page->getFlashContents();

        $flash = new FlashContent();
        $this->flashForm = new FlashContentForm($flash);

        $this->processFlashContentForm($request, $this->flashForm);

    }

protected function processFlashContentForm($request, $form)
    {
      if ( $form->isSubmitted( $request ) ) {
     $form->bind( $request->getParameter( $form->getName() ), $request->getFiles( $form->getName() ) );
     if ( $form->isValid() ) {
  $form->save();
  $this->getUser()->setFlash( 'notice', $form->isNew() ? 'Added.' : 'Updated.' );
  $this->redirect( '@home' );
     }
 }
    }

Before binding my parameters, everything's fine, $request->getFiles($form->getName()) returns my files. But afterwards, $form->getValue('filename') returns the string "Array".

Did it happen to any of you guys or do you see anything wrong with my code?

Edit: I added the fact that I'm embedding another form, which may be the problem (see Form code above).

2 Answers 2

3

Alright, I got it. I wasn't properly declaring my validator.

What i should've done is:

$this->setValidator('filename', new sfValidatorFile(array(
  'mime_types' => 'web_images',
  'path' => sfConfig::get('sf_upload_dir').'/flash',
)));

Silly mistake, I hope that will help those who have the same problem.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks It was quite helpful...As I was having the same problem and got fixed when I used your version..! :D :P
0

Alternatively you can use;

$this->validatorSchema['filename']

in place of;

$this->setValidator['filename']

1 Comment

While using validatorSchema I was having the problem...Got solved when I used the above answer version..!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.