Commit b163f2a4 by Qiang Xue

...

parent 47fe25d4
...@@ -138,7 +138,7 @@ class Component extends \yii\base\Object ...@@ -138,7 +138,7 @@ class Component extends \yii\base\Object
$this->$setter($value); $this->$setter($value);
return; return;
} elseif (strncmp($name, 'on ', 3) === 0) { // on event } elseif (strncmp($name, 'on ', 3) === 0) { // on event
$name = substr($name, 3); $name = trim(substr($name, 3));
$this->getEventHandlers($name)->add($value); $this->getEventHandlers($name)->add($value);
return; return;
} else { // behavior property } else { // behavior property
...@@ -364,14 +364,17 @@ class Component extends \yii\base\Object ...@@ -364,14 +364,17 @@ class Component extends \yii\base\Object
* This method represents the happening of an event. It invokes * This method represents the happening of an event. It invokes
* all attached handlers for the event. * all attached handlers for the event.
* @param string $name the event name * @param string $name the event name
* @param Event $event the event parameter * @param Event $event the event parameter. If not set, a default [[Event]] object will be created.
* @throws Exception if the event is undefined or an event handler is invalid. * @throws Exception if the event is undefined or an event handler is invalid.
*/ */
public function trigger($name, $event) public function trigger($name, $event = null)
{ {
$this->ensureBehaviors(); $this->ensureBehaviors();
if (isset($this->_e[$name])) { if (isset($this->_e[$name])) {
if ($event instanceof Event) { if ($event === null) {
$event = new Event($this);
$event->name = $name;
} elseif ($event instanceof Event) {
$event->name = $name; $event->name = $name;
$event->handled = false; $event->handled = false;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment