这是我的行为的类events()
方法。当我触发事件第二个处理程序sendMailHanlder
时,即被调用并且它忽略anotherOne
. 我相信,第二个会覆盖第一个。如何解决此问题以便调用两个事件处理程序?
// UserBehavior.php
public function events()
{
return [
Users::EVENT_NEW_USER => [$this, 'anotherOne'],
Users::EVENT_NEW_USER => [$this, 'sendMailHanlder'],
];
}
// here are two handlers
public function sendMailHanlder($e)
{
echo ";
}
public function anotherOne($e)
{
echo 'another one';
}
需要注意的一件事是我将此行为附加到我的Users.php
模型中。我尝试使用模型的init()
方法添加两个处理程序。这样两个处理程序都被调用了。这是我的初始化代码。
public function init()
{
$this->on(self::EVENT_NEW_USER, [$this, 'anotherOne']);
$this->on(self::EVENT_NEW_USER, [$this, 'sendMailHanlder']);
}