我有這個方法在我的實體:更新前
/**
* @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作品,但當我更新對象 - 它不。爲什麼?
如果我沒有@ORM \ HasLifeCycleCallbacks那麼prepersist也不會工作,正如我所說 - 它完美的工作。刪除尾部()並沒有改變任何東西。我知道我可以用事件監聽器來做,但我想知道它爲什麼不起作用? – user2394156