From 6a279dd8a40ff4caf5736e6d429220e3e2439ed5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=B7=87?= Date: Mon, 25 Sep 2017 22:32:51 +0800 Subject: [PATCH 1/4] Update concept-events.md --- docs/guide-zh-CN/concept-aliases.md | 3 --- docs/guide-zh-CN/concept-events.md | 27 +++++++++++++-------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/docs/guide-zh-CN/concept-aliases.md b/docs/guide-zh-CN/concept-aliases.md index 23e8b1ab51..5a8b549c89 100644 --- a/docs/guide-zh-CN/concept-aliases.md +++ b/docs/guide-zh-CN/concept-aliases.md @@ -5,9 +5,6 @@ 一个别名必须以 `@` 字符开头,以区别于传统的文件路径和 URL。 Yii 预定义了大量可用的别名。例如,别名 `@yii` 指的是 Yii 框架本身的安装目录,而 `@web` 表示的是当前运行应用的根 URL。 -Yii has many pre-defined aliases already available. For example, the alias `@yii` represents the installation path of -the Yii framework; `@web` represents the base URL for the currently running Web application. - 定义别名 ---------------- diff --git a/docs/guide-zh-CN/concept-events.md b/docs/guide-zh-CN/concept-events.md index 19cec2a65e..8c8a66ecda 100644 --- a/docs/guide-zh-CN/concept-events.md +++ b/docs/guide-zh-CN/concept-events.md @@ -59,8 +59,8 @@ $foo->on(Foo::EVENT_HELLO, function ($event) { }); ``` -You may also attach event handlers through [configurations](concept-configurations.md). For more details, please -refer to the [Configurations](concept-configurations.md#configuration-format) section. +你也可以通过 [配置](concept-configurations.md) 附加事件处理器。 请 +参考 [配置的格式](concept-configurations.md#configuration-format) 小节了解更多. 附加事件处理器时可以提供额外数据作为 [[yii\base\Component::on()]] 方法的第三个参数。 @@ -252,13 +252,13 @@ Event::off(Foo::className(), Foo::EVENT_HELLO); ``` -Events using interfaces +使用接口事件 ------------- -There is even more abstract way to deal with events. You can create a separated interface for the special event and -implement it in classes, where you need it. +有更多的抽象方式来处理事件。你可以为特殊的事件创建一个独立的接口, +然后在你需要的类中实现它。 -For example, we can create the following interface: +例如,我们可以先创建下面这个接口: ```php namespace app\interfaces; @@ -269,7 +269,7 @@ interface DanceEventInterface } ``` -And two classes, that implement it: +然后在两个类中实现: ```php class Dog extends Component implements DanceEventInterface @@ -291,8 +291,7 @@ class Developer extends Component implements DanceEventInterface } ``` -To handle the `EVENT_DANCE`, triggered by any of these classes, call [[yii\base\Event::on()|Event::on()]] and -pass the interface class name as the first argument: +要处理由这些类触发的 `EVENT_DANCE` ,调用 [[yii\base\Event::on()|Event::on()]] 并将接口类名作为第一个参数: ```php Event::on('app\interfaces\DanceEventInterface', DanceEventInterface::EVENT_DANCE, function ($event) { @@ -300,7 +299,7 @@ Event::on('app\interfaces\DanceEventInterface', DanceEventInterface::EVENT_DANCE }); ``` -You can trigger the event of those classes: +你可以在这些类中触发这个事件: ```php // trigger event for Dog class @@ -310,20 +309,20 @@ Event::trigger(Dog::className(), DanceEventInterface::EVENT_DANCE); Event::trigger(Developer::className(), DanceEventInterface::EVENT_DANCE); ``` -But please notice, that you can not trigger all the classes, that implement the interface: +但是请注意, 你不能让所有实现这个接口的类都触发事件: ```php -// DOES NOT WORK. Classes that implement this interface will NOT be triggered. +// 不会生效. 实现此接口的类不会触发事件。 Event::trigger('app\interfaces\DanceEventInterface', DanceEventInterface::EVENT_DANCE); ``` To detach event handler, call [[yii\base\Event::off()|Event::off()]]. For example: ```php -// detaches $handler +// 移除事件处理器 Event::off('app\interfaces\DanceEventInterface', DanceEventInterface::EVENT_DANCE, $handler); -// detaches all handlers of DanceEventInterface::EVENT_DANCE +// 移除所有 `EVENT_DANCE` 的处理器 Event::off('app\interfaces\DanceEventInterface', DanceEventInterface::EVENT_DANCE); ``` From 610bbe923d632af4cbbe62d2c41c735074999ddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=B7=87?= Date: Mon, 25 Sep 2017 22:37:24 +0800 Subject: [PATCH 2/4] fix line Keep the number of rows consistent --- docs/guide-zh-CN/concept-events.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/guide-zh-CN/concept-events.md b/docs/guide-zh-CN/concept-events.md index 8c8a66ecda..8d5fcb848d 100644 --- a/docs/guide-zh-CN/concept-events.md +++ b/docs/guide-zh-CN/concept-events.md @@ -291,7 +291,8 @@ class Developer extends Component implements DanceEventInterface } ``` -要处理由这些类触发的 `EVENT_DANCE` ,调用 [[yii\base\Event::on()|Event::on()]] 并将接口类名作为第一个参数: +要处理由这些类触发的 `EVENT_DANCE` ,调用 [[yii\base\Event::on()|Event::on()]] +并将接口类名作为第一个参数: ```php Event::on('app\interfaces\DanceEventInterface', DanceEventInterface::EVENT_DANCE, function ($event) { From b34dc38ab8f01ac9adcb7ab5dadb2f7ea6e9ce7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=B7=87?= Date: Tue, 26 Sep 2017 10:12:20 +0800 Subject: [PATCH 3/4] Update concept-events.md correct mistakes --- docs/guide-zh-CN/concept-events.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/guide-zh-CN/concept-events.md b/docs/guide-zh-CN/concept-events.md index 8d5fcb848d..b8e32ca244 100644 --- a/docs/guide-zh-CN/concept-events.md +++ b/docs/guide-zh-CN/concept-events.md @@ -317,13 +317,13 @@ Event::trigger(Developer::className(), DanceEventInterface::EVENT_DANCE); Event::trigger('app\interfaces\DanceEventInterface', DanceEventInterface::EVENT_DANCE); ``` -To detach event handler, call [[yii\base\Event::off()|Event::off()]]. For example: +调用 [[yii\base\Event::off()|Event::off()]] 移除事件处理器。 例如: ```php -// 移除事件处理器 +// 移除 $handler Event::off('app\interfaces\DanceEventInterface', DanceEventInterface::EVENT_DANCE, $handler); -// 移除所有 `EVENT_DANCE` 的处理器 +// 移除所有 `DanceEventInterface::EVENT_DANCE` 的处理器 Event::off('app\interfaces\DanceEventInterface', DanceEventInterface::EVENT_DANCE); ``` From 5bb4f30b70568215edeb7e18391f27200c423274 Mon Sep 17 00:00:00 2001 From: cuiliang Date: Tue, 26 Sep 2017 01:05:53 -0500 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A0=87=E7=82=B9?= =?UTF-8?q?=E7=AC=A6=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/guide-zh-CN/concept-events.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/guide-zh-CN/concept-events.md b/docs/guide-zh-CN/concept-events.md index b8e32ca244..40073ec736 100644 --- a/docs/guide-zh-CN/concept-events.md +++ b/docs/guide-zh-CN/concept-events.md @@ -300,7 +300,7 @@ Event::on('app\interfaces\DanceEventInterface', DanceEventInterface::EVENT_DANCE }); ``` -你可以在这些类中触发这个事件: +你可以在这些类中触发这个事件: ```php // trigger event for Dog class @@ -310,14 +310,14 @@ Event::trigger(Dog::className(), DanceEventInterface::EVENT_DANCE); Event::trigger(Developer::className(), DanceEventInterface::EVENT_DANCE); ``` -但是请注意, 你不能让所有实现这个接口的类都触发事件: +但是请注意, 你不能让所有实现这个接口的类都触发事件: ```php -// 不会生效. 实现此接口的类不会触发事件。 +// 不会生效。实现此接口的类不会触发事件。 Event::trigger('app\interfaces\DanceEventInterface', DanceEventInterface::EVENT_DANCE); ``` -调用 [[yii\base\Event::off()|Event::off()]] 移除事件处理器。 例如: +调用 [[yii\base\Event::off()|Event::off()]] 移除事件处理器。例如: ```php // 移除 $handler