Class-based events doc fix

This commit is contained in:
Klimov Paul
2016-08-30 13:14:00 +03:00
parent e97c798a4f
commit d55d8f6070
7 changed files with 9 additions and 9 deletions

View File

@ -237,7 +237,7 @@ invocación de los gestores de eventos a nivel de clase.
use yii\base\Event;
Event::on(Foo::className(), Foo::EVENT_HELLO, function ($event) {
echo $event->sender; // displays "app\models\Foo"
var_dump($event->sender); // displays "null"
});
Event::trigger(Foo::className(), Foo::EVENT_HELLO);

View File

@ -200,7 +200,7 @@ Vous pouvez déclencher un événement au *niveau de la classe* en appelant la m
use yii\base\Event;
Event::on(Foo::className(), Foo::EVENT_HELLO, function ($event) {
echo $event->sender; // displays "app\models\Foo"
var_dump($event->sender); // displays "null"
});
Event::trigger(Foo::className(), Foo::EVENT_HELLO);

View File

@ -227,7 +227,7 @@ Event::on(ActiveRecord::className(), ActiveRecord::EVENT_AFTER_INSERT, function
use yii\base\Event;
Event::on(Foo::className(), Foo::EVENT_HELLO, function ($event) {
echo $event->sender; // "app\models\Foo" を表示
var_dump($event->sender); // "null" を表示
});
Event::trigger(Foo::className(), Foo::EVENT_HELLO);

View File

@ -206,7 +206,7 @@ Você pode disparar um evento de *nível de classe* chamando o método estático
use yii\base\Event;
Event::on(Foo::className(), Foo::EVENT_HELLO, function ($event) {
echo $event->sender; // displays "app\models\Foo"
var_dump($event->sender); // displays "null"
});
Event::trigger(Foo::className(), Foo::EVENT_HELLO);

View File

@ -202,13 +202,13 @@ Event::on(ActiveRecord::className(), ActiveRecord::EVENT_AFTER_INSERT, function
use yii\base\Event;
Event::on(Foo::className(), Foo::EVENT_HELLO, function ($event) {
echo $event->sender; // выводит "app\models\Foo"
var_dump($event->sender); // выводит "null"
});
Event::trigger(Foo::className(), Foo::EVENT_HELLO);
```
Обратите внимание, что в данном случае `$event->sender` ссылается на имя класса, который инициировал событие, а не на его экземпляр.
Обратите внимание, что в данном случае `$event->sender` имеет значение `null` вместо экзепляра класса, который инициировал событие.
> Note: Поскольку обработчики на уровне класса отвечают на события, инициируемые всеми экземплярами этого класса и всех его потомков, их следует использовать с осторожностью, особенно в случае базовых классов низкого уровня, таких как [[yii\base\Object]].

View File

@ -196,7 +196,7 @@ Event::on(ActiveRecord::className(), ActiveRecord::EVENT_AFTER_INSERT, function
use yii\base\Event;
Event::on(Foo::className(), Foo::EVENT_HELLO, function ($event) {
echo $event->sender; // 显示 "app\models\Foo"
var_dump($event->sender); // 显示 "null"
});
Event::trigger(Foo::className(), Foo::EVENT_HELLO);

View File

@ -230,13 +230,13 @@ handlers only. For example:
use yii\base\Event;
Event::on(Foo::className(), Foo::EVENT_HELLO, function ($event) {
echo $event->sender; // displays "app\models\Foo"
var_dump($event->sender); // displays "null"
});
Event::trigger(Foo::className(), Foo::EVENT_HELLO);
```
Note that, in this case, `$event->sender` refers to the name of the class triggering the event instead of an object instance.
Note that, in this case, `$event->sender` is `null` instead of an object instance.
> Note: Because a class-level handler will respond to an event triggered by any instance of that class, or any child
classes, you should use it carefully, especially if the class is a low-level base class, such as [[yii\base\Object]].