标签:
namespace app\components; use yii\base\Component; use yii\base\Event; class MessageEvent extends Event { public $message; } class Mailer extends Component { const EVENT_MESSAGE_SENT = ‘messageSent‘; public function send($message) { // ...发送 $message 的逻辑... $event = new MessageEvent; $event->message = $message; $this->trigger(self::EVENT_MESSAGE_SENT, $event); } }
个人理解:Yii2中的事件很像thinkphp中的钩子
标签:
原文地址:http://www.cnblogs.com/LoveJulin/p/5562799.html