【发布时间】:2014-03-25 19:47:17
【问题描述】:
我的收藏表单类型没有什么问题。
我有一对多的关系(产品和产品图片)
我认为问题出在我的 productImages 实体中(如果可以解决的话)
我的产品图片:
class produktImage
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* @Assert\File(maxSize="6000000")
*/
public $file;
/**
* @ORM\ManyToOne(targetEntity="product", inversedBy="tags")
*/
protected $product;
还有最重要的方法:
public function upload()
{
$this->name = trim(date("dmyGis").rand(1,99999999).'_'.$this->file->getClientOriginalName());
$this->file->move($this->getUploadRootDir(), $this->name);
$move = new resizeImg(1280, 3000, $this->name, $this->getUploadRootDir(), null);
$move->setThumbial(550, 2000, $this->getUploadRootDir().'../small/', null);
$move->setThumbial(200, 2000, $this->getUploadRootDir().'../thumb/', null);
$this->file = null;
}
Form productImage 只有文件字段。
我的产品实体(最重要的方法)
public function addPhotosum($photos)
{
$photos->setProdukt($this);
$photos->upload($this);
$this->photos->add($photos);
return $this;
}
public function removePhotosum($photos)
{
$this->photos->removeElement($photos);
$photos->removeImg();
}
好的,但我的问题在哪里。 当我尝试添加或删除文件时,一切正常。 如果我尝试编辑文件没有任何反应。名称和文件不变。
我认为这是因为 Product 看不到名称的更改(名称仅存储在 db 中),但我不知道如何告诉他“当文件不同时更改名称和文件”。
我可以使用 preUpdate 或其他东西吗?
有人遇到过类似问题吗?
【问题讨论】:
标签: forms symfony collections