src/base/Component.php
public function on($name, $handler, array $params = [], $append = true)
    {
        $this->ensureBehaviors();

        if (strpos($name, '*') !== false) {
            if ($append || empty($this->_eventWildcards[$name])) {
                $this->_eventWildcards[$name][] = [$handler, $params];
            } else {
                array_unshift($this->_eventWildcards[$name], [$handler, $params]);
            }
            return;
        }

        if ($append || empty($this->_events[$name])) {
            $this->_events[$name][] = [$handler, $params];
        } else {
            array_unshift($this->_events[$name], [$handler, $params]);
        }
    }
public function on($name, $handler, array $params = [], $append = true)
    {
        $this->ensureBehaviors();

        if (strpos($name, '*') !== false) {
            if ($append || empty($this->_eventWildcards[$name])) {
                $this->_eventWildcards[$name][] = [$handler, $params];
            } else {
                array_unshift($this->_eventWildcards[$name], [$handler, $params]);
            }
            return;
        }

        if ($append || empty($this->_events[$name])) {
            $this->_events[$name][] = [$handler, $params];
        } else {
            array_unshift($this->_events[$name], [$handler, $params]);
        }
    }
public function on ( $ name , $ handler , array $ params = [ ] , $ append = true ) { $ this -> ensureBehaviors ( ) ; if ( strpos ( $ name , '*' ) !== false ) { if ( $ append || empty ( $ this -> _eventWildcards [ $ name ] ) ) { $ this -> _eventWildcards [ $ name ] [ ] = [ $ handler , $ params ] ; } else { array_unshift ( $ this -> _eventWildcards [ $ name ] , [ $ handler , $ params ] ) ; } return ; } if ( $ append || empty ( $ this -> _events [ $ name ] ) ) { $ this -> _events [ $ name ] [ ] = [ $ handler , $ params ] ; } else { array_unshift ( $ this -> _events [ $ name ] , [ $ handler , $ params ] ) ; } }
Attaches an event handler to an event.

The event handler must be a valid PHP callback. The following are
some examples:

```
function ($event) { ... }         // anonymous function
[$object, 'handleClick']          // $object->handleClick()
['Page', 'handleClick']           // Page::handleClick()
'handleClick'                     // global function handleClick()
```

The event handler must be defined with the following signature,

```
function ($event)
```

where `$event` is an [[Event]] object which includes parameters associated with the event.

Since 2.0.14 you can specify event name as a wildcard pattern:

```php
$component->on('event.group.*', function ($event) {
Yii::debug($event->name . ' is triggered.');
});
```

@param string $name the event name
@param callable $handler the event handler
@param array $params the parameters 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]].
@param bool $append 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.
@see off()
Attaches an event handler to an event .