use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\Debug\Debug; use Symfony\Component\EventDispatcher\Event; $loader = require_once __DIR__.'/../app/bootstrap.php.cache'; Debug::enable(); $EventDispatcher = new EventDispatcher(); class TestListener { public function onTestAction(Event $event) { echo $event->getValue(); } } $TestListener = new TestListener(); $TestListener, 'onTestAction' )); class TestEvent extends Event { private $value; public function setValue($value) { $this->value = $value; } public function getValue() { return $this->value; } } $event = new TestEvent(); $event->setValue('Hello world!'); $EventDispatcher->dispatch('a1', $event);
Комментарии
symfony 2 events
Ок! Я создал файл с этим скриптом и поместил его в папку web моего symfony 2 проекта. И в результате выполнения получил:
- Войдите или зарегистрируйтесь, чтобы оставлять комментарии
- Войдите или зарегистрируйтесь, чтобы оставлять комментарии