开发者

Symfony sfWidgetFormInputFile save file path to bd

I'm using the symfony framework and I want to mak开发者_开发技巧e a very simple thing...add an input type=file field to a form so a file can be uploaded an then save the path to bd so latter the user is able to download it.

Should be simple but for some reason I'm having an "An object with the same "linkToFile" already exist." error. The linkToFile field on the bd is unique and it seems that the value retrieved by the isfWidgetFormInputFile is equal to another which is odd because the only values that I presently have in the bd are null. And this only happens if a file is selected if the field is left blank there is no problem.

The code I have is:

public function configure()
  {
      //the slug field can't be edited
      unset($this['slug']);
      $this->setWidget('linkToFile', new sfWidgetFormInputFile(array(), array()));
      $this->getWidget('linkToFile')->setLabel('Document Upload');
      $this->setValidator('linkToFile', new sfValidatorFile(array("required"=>false), array()));
      $this->setDefault('linkToFile', $this->getObject()->getLinkToFile());

  }


What happens if you take the unique setting of that field?

It's probably throwing that error if you have multiple rows, since there will be mulitiple linkToFile values that are set to NULL

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜