public on ( string $name, callable $handler, mixed $data = null, boolean $append = true ) | ||
$name | string | the event name |
$handler | callable | the event handler |
$data | mixed | the data to be passed to the event handler when the event is triggered. When the event handler is invoked, this data can be accessed via [[Event::data]]. |
$append | boolean | whether to append new event handler to the end of the existing handler list. If false, the new handler will be inserted at the beginning of the existing handler list. |
public function on($name, $handler, $data = null, $append = true)
{
$this->ensureBehaviors();
if ($append || empty($this->_events[$name])) {
$this->_events[$name][] = [$handler, $data];
} else {
array_unshift($this->_events[$name], [$handler, $data]);
}
}
public function on($name, $handler, $data = null, $append = true) { $internalHandler = static::INTERNAL_HANDLER . $this->_counter++; $this->_handlers[$name][$internalHandler] = $handler; parent::on($name, [$this, $internalHandler], $data, $append); }