尝试在doctrine listener中获取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'));
...
}
}
答案 0 :(得分:0)
所以,json_decode($request->getContent(), true)
给了我正确的参数。返回一组后期数据。奇怪的是$request->request->all()
也应该有效。