试图在教义监听器中获取 POST 参数。但是,得到一个空数组。也尝试将请求推送到控制器中的 requeststack。但是,仍然是空的。
class OrderListener
{
private $requestStack;
public function __construct(RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}
public function postPersist(LifecycleEventArgs $args)
{
$entity = $this->getObject();
if ($entity instanceof Order) {
$request = $this->requestStack->getCurrentRequest();
$this->handleEvent($entity, $args->getEntityManager());
}
}
public function handleEvent(Order $order, EntityManagerInterface $em)
{
// here $request->request->all() is empty
$request = $this->requestStack->getCurrentRequest();
$transaction = new Transaction();
$transaction->setOrder($order);
$transaction->setRemoteId($request->request->get('stripeInvoiceId'));
...
}
}