0

我在 symfony 中有一个项目,我想让我的用户为他们的“头像”字段上传一张图片。我发现了许多关于如何使用以下架构“扩展”我拥有的表的帖子:

Member:
  inheritance:
    type:             column_aggregation
    extends:          sfGuardUser  
columns:
    idmember:    { type: integer }
    birthday:    { type: date }
    avatar:      { type: string(255) }
    bio:         { type: string(255) }

列被添加到表中就好了,但是当我将小部件更改为时sfWidgetFormInputFileEditable它会中断。这是 Form.class 文件:

  $file_src = $this->getObject()->getAvatar();
  if ($file_src == '')
  {
    $file_src = 'default_image.png';
  }

  $this->widgetSchema['avatar'] = new sfWidgetFormInputFileEditable(array(
    'label'     => ' ',
    'file_src'  => '/uploads/avatar/'.$file_src,
    'is_image'  => true,
    'edit_mode' => true,
    'template'  => '<div>%file%<br />%input%</div>',
  ));

和形式的“保存”功能:

if($this->isModified())
    {
      $uploadDir = sfConfig::get('sf_upload_dir');
      $thumbnail = new sfThumbnail(150, 150);
      $thumbnail2 = new sfThumbnail(800, 800);
      if($this->getAvatar())
      {
        $thumbnail->loadFile($uploadDir.'/avatar/'.$this->getAvatar());
        $thumbnail->save($uploadDir.'/avatar/thumbnail/'. $this->getAvatar());
        $thumbnail2->loadFile($uploadDir.'/avatar/'.$this->getAvatar());
        $thumbnail2->save($uploadDir.'/avatar/big/'. $this->getAvatar());
      }
   }  

当我提交表单时,我收到以下错误消息:

This form is multipart, which means you need to supply a files array as the bind() method second argument.

4

1 回答 1

1

在绑定表单的操作中,您应该使用如下内容:

$form->bind($request->getParamater($form->getName()), $request->getFiles($form->getName()));

所以你需要将上传的文件作为第二个参数传递给bind方法。

于 2013-03-06T08:52:32.573 回答