在两个事件调用之间保留数据

时间:2016-01-12 07:37:23

标签: php symfony events

我有一个类,哪些方法订阅了两个事件

<?php

namespace AppBundle\Listener;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;

class WatermarkListener implements EventSubscriberInterface
{
    private $data;

    public static function getSubscribedEvents()
    {
        return array(
            FormEvents::PRE_SUBMIT => 'onPreSetData',
        );
    }

    public function postUpload(Event $event)
    {
        dump($event);
        dump($this->data);
        exit;
    }

    public function onPresetData(FormEvent $event)
    {
        $this->data = $event->getData();
        dump($this->data);
    }
}
首先触发

FormEvents::PRE_SUBMIT并填充$this->data问题是当第二个事件postUpload被触发时,$this->data的值为空。如何在这两个事件调用之间保留$this->data中的数据?

0 个答案:

没有答案
相关问题