0

试图在教义监听器中获取 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'));
       ...
    }
}
4

1 回答 1

0

所以,json_decode($request->getContent(), true)给了我正确的参数。返回一个帖子数据数组。奇怪的是也$request->request->all()应该起作用。

于 2017-10-31T17:44:54.790 回答