views:

547

answers:

2

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).

+1  A: 

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.

Guillaume Flandre
A: 

Alternatively you can use;

$this->validatorSchema['filename']

in place of;

$this->setValidator['filename']
Lashae