yii事件
控制器:
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事件的更多相关文章
- 简单理解yii事件
https://blog.csdn.net/qq43599939/article/details/80363827 通过观察者来理解yii事件 测试 class TestController ext ...
- YII 事件event和行为Behavior
To declare an event in your CComponent child class, you should add a method with aname starting with ...
- YII事件EVENT示例
模型中/** * 在初始化时进行事件绑定 */ public function init() { $this->on(self::EVENT_HELLO,[$this,'sendMail']); ...
- 与《YII框架》不得不说的故事—5篇目录
与<YII框架>不得不说的故事—基础篇 第1章 课程目标 1-1 课程目标 (00:54) 第2章 课前知识准备 2-1 YII的启动和安装 (05:12) 2-2 YII请求处理流程 ( ...
- Yii2之事件
众所周知,yii的三大特性是:属性.事件.行为,上一篇博文简单讲解了yii中的属性,本文接着讲讲yii的事件. 事件是代码解耦的一种方式,设计业务流程的一种模式.在yii2.0中,通过Yii\base ...
- YII自定义第三方扩展
cat.php <?php /** * Created by PhpStorm. * Date: 2016/5/25 * Time: 15:23 */ namespace vendor\anim ...
- JNI详解---从不懂到理解
转载:https://blog.csdn.net/hui12581/article/details/44832651 Chap1:JNI完全手册... 3 Chap2:JNI-百度百科... 11 C ...
- Yii框架zii.widgets.grid自定义按钮,ajax触发事件并提示
相关类手册: http://www.yiichina.com/api/CButtonColumn buttons 属性 public array $buttons; the configurati ...
- YII框架分析笔记2:组件和事件行为管理
Yii是一个基于组件.用于开发大型 Web 应用的高性能 PHP 框架.CComponent几乎是所有类的基类,它控制着组件与事件的管理,其方法与属性如下,私有变量$_e数据存放事件(evnet,有些 ...
随机推荐
- artdialog
<html><head><meta http-equiv="Content-Type" content="text/html; charse ...
- iOS Waxpatch项目(动态更新)
我的iOS Waxpatch项目地址https://github.com/piaojin/iOS-WaxPatch
- 教你几种在SQLServer中删除重复数据方法(转)
转载地址:http://www.jb51.net/article/22980.htm 方法一 复制代码 代码如下: declare @max integer,@id integer declare c ...
- 【leetcode】Two Sum
题目简述: Given an array of integers, find two numbers such that they add up to a specific target number ...
- 适配器模式/adapter模式/结构型模式
定义 将类的接口转化为客户端希望的另外一个接口,使得原本由于接口不兼容而不能一起工作的类可以一起工作,别名Wrapper(包装器). 适配器模式,最终改变一个已有对象的接口. 使用场景 当有那么个类, ...
- Install MySQL on CentOS 7
原文:https://devops.profitbricks.com/tutorials/install-mysql-on-centos-7/ 1.下载mysql 在mysql官网选择适合的mysql ...
- 廖雪峰js教程笔记14 file文件操作
在HTML表单中,可以上传文件的唯一控件就是<input type="file">. 注意:当一个表单包含<input type="file" ...
- ios8 设置单元格分割线无效
原来: [self.tableView setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];//分隔线紧贴左右边框 || [self.tableView s ...
- wenbenfenlei
ICTCLAS: 该分词系统的主要思想是先通过CHMM(层叠形马尔可夫模型)进行分词,通过分层,既增加了分词的准确性,又保证了分词的效率.基本思路是:先进行原子切分,然后在此基础上进行N-最短路径粗切 ...
- Page-encoding specified in XML prolog (UTF-8) is different from that specified in page directive (utf-8)
org.apache.jasper.JasperException:xxx.jsp(1,1) Page-encoding specified in XML prolog (UTF-8) is diff ...