0
我想監聽從prePersist()
訪問setUser()
方法OrderHasComment公共方法,但我得到這個錯誤:無法訪問從prePersist事件偵聽器
FatalErrorException: Error: Call to undefined method PL\OrderBundle\Entity\Order::setUser() in /var/www/html/apps/portal_de_logistica/src/PL/OrderBundle/Listener/OrderHasCommentListener.php line 23
這是方法:
/**
*
* @param LifecycleEventArgs $args
*/
public function prePersist(LifecycleEventArgs $args) {
$entity = $args->getEntity();
$user = $this->container->get('security.context')->getToken()->getUser();
$entity->setUser($user);
}
爲什麼它訪問Order
而不是OrderHasComment
?我如何解決這個問題?我做錯了什麼?