$component = new \yii\base\Component();
$component->on('test', function($event) {
print_r($event->data);
}, ['foo'=>'123']);
$component->trigger('test', new \yii\base\Event(['data'=>['bar'=>'456']]));
['foo'=>'123', 'bar'=>'456']
['foo'=>'123']
I think the developer should can pass an additional parameters via trigger too. Not only via on.
| Q | A |
| --- | --- |
| Yii version | 2.0.9 |
| PHP version | 5.5.9 |
| Operating system | Ubuntu |
This is expected. Event::data is always overridden by the values from event handler.
It is clearly documented:
https://github.com/yiisoft/yii2/blob/master/framework/base/Event.php#L45-L49
@klimov-paul but it's a silly behavior!
we should have this ability to pass data when we want to trigger an event
Most helpful comment
@klimov-paul but it's a silly behavior!
we should have this ability to pass data when we want to trigger an event