控制器:

public function actionTests1(){
  $c = new \app\components\cat();
  $m = new \app\components\mou;
  $g = new \app\components\dog;
  Event::on(\app\components\cat::className(),'miao',[$m,'run']);
  // Event::on(cat::className(),'miao',function(){echo 11;});
  // $c->on('miao',[$m,'run']);
  // $c->on('miao',[$g,'look']);
  $c->shut();
}

------------------------------

<?php
namespace app\components;
use \yii\base\Event;
class myevent extends Event{
  public $message;
}
class cat extends \yii\base\Component{
  public function shut(){
    echo 'miaomiaomiao';
    $me = new myevent();
    $me->message = 'sdasdas';
    $this->trigger('miao',$me);
  }
}

-----------------------

<?php
namespace app\components;
class mou{
  public function run($me){
    echo $me->message;
    echo 'run run run';
  }
}

-----

说明:事件使用场景!在不需要返回值的场景下可使用事件进行处理!

yii事件的更多相关文章

  1. 简单理解yii事件

    https://blog.csdn.net/qq43599939/article/details/80363827  通过观察者来理解yii事件 测试 class TestController ext ...

  2. YII 事件event和行为Behavior

    To declare an event in your CComponent child class, you should add a method with aname starting with ...

  3. YII事件EVENT示例

    模型中/** * 在初始化时进行事件绑定 */ public function init() { $this->on(self::EVENT_HELLO,[$this,'sendMail']); ...

  4. 与《YII框架》不得不说的故事—5篇目录

    与<YII框架>不得不说的故事—基础篇 第1章 课程目标 1-1 课程目标 (00:54) 第2章 课前知识准备 2-1 YII的启动和安装 (05:12) 2-2 YII请求处理流程 ( ...

  5. Yii2之事件

    众所周知,yii的三大特性是:属性.事件.行为,上一篇博文简单讲解了yii中的属性,本文接着讲讲yii的事件. 事件是代码解耦的一种方式,设计业务流程的一种模式.在yii2.0中,通过Yii\base ...

  6. YII自定义第三方扩展

    cat.php <?php /** * Created by PhpStorm. * Date: 2016/5/25 * Time: 15:23 */ namespace vendor\anim ...

  7. JNI详解---从不懂到理解

    转载:https://blog.csdn.net/hui12581/article/details/44832651 Chap1:JNI完全手册... 3 Chap2:JNI-百度百科... 11 C ...

  8. Yii框架zii.widgets.grid自定义按钮,ajax触发事件并提示

    相关类手册: http://www.yiichina.com/api/CButtonColumn   buttons 属性 public array $buttons; the configurati ...

  9. YII框架分析笔记2:组件和事件行为管理

    Yii是一个基于组件.用于开发大型 Web 应用的高性能 PHP 框架.CComponent几乎是所有类的基类,它控制着组件与事件的管理,其方法与属性如下,私有变量$_e数据存放事件(evnet,有些 ...

随机推荐

  1. VC++ 制作一个简易的控制台时钟应用

    1.下载EasyX Library for C++ (http://www.easyx.cn/) 直接下载:EasyX_20151015(beta) EasyX 绘图库目前支持 Visual C++ ...

  2. (2016弱校联盟十一专场10.3) A.Best Matched Pair

    题目链接 #include<cstdio> #include<cstring> #include<algorithm> #include<stack> ...

  3. 【XLL 框架库函数】 TempErr/TempErr12

    创建一个包含了 Excel 工作表错误的临时 XLOPER/XLOPER12 原型 LPXLOPER TempErr(WORD err); LPXLOPER12 TempErr12(BOOL err) ...

  4. Java中的位运算

    昨天去面试的时候做到了一道Java的位运算题目,发现有个运算符不懂:">>>",今天特地查了一下,并小结一下常见的位运算符号: ~  按位非(NOT)(一元运算) ...

  5. windows 10 设置

    精简应用 邮件和日历: Get-AppxPackage *communi* | Remove-AppxPackage 新闻: Get-AppxPackage *bing* | Remove-AppxP ...

  6. WPF MVVM中在ViewModel中关闭或者打开Window

    这篇博客将介绍在MVVM模式ViewModel中关闭和打开View的方法. 1. ViewModel中关闭View public class MainViewModel { public Delega ...

  7. Leetcode Substring with Concatenation of All Words

    You are given a string, S, and a list of words, L, that are all of the same length. Find all startin ...

  8. 【JAVA】FOR UPDATE 和 FOR UPDATE NOWAIT 区别 (转)

    1.for update 和 for update nowait 的区别:首先一点,如果只是select 的话,Oracle是不会加任何锁的,也就是Oracle对 select 读到的数据不会有任何限 ...

  9. 25 Killer Actions to Boost Your Self-Confidence

    25 Killer Actions to Boost Your Self-Confidence Once we believe in ourselves, we can risk curiosity, ...

  10. i2c协议

    i2c协议 http://blog.csdn.net/g_salamander/article/details/8016698 总线设备驱动模型 http://blog.csdn.net/u01395 ...