我的实体中有这个方法:
/**
* @ORM\PreUpdate()
* @ORM\PrePersist()
*/
public function preStore() {
if ($this->getPictureFile()) {
$newFilename = sha1(mt_rand());
$newFilename = $newFilename . '.' . ($this->getPictureFile()->guessExtension());
$this->setPictureFilename($newFilename);
}
}
当持久化对象时,一切正常,但在更新时根本不会触发该方法,我以这种方式对其进行了测试:
/**
* @ORM\PreUpdate()
* @ORM\PrePersist()
*/
public function preStore() { var_dump('asdasdasdadsdasdas');
if ($this->getPictureFile()) {
$newFilename = sha1(mt_rand());
$newFilename = $newFilename . '.' . ($this->getPictureFile()->guessExtension());
$this->setPictureFilename($newFilename);
}
}
并且坚持 var_dump 有效,但是当我更新对象时 - 它没有。为什么?