コード例 #1
0
 /**
  * 类级事件的程序处理
  */
 public function actionClass()
 {
     $person1 = new Person();
     $person2 = new Person();
     $processer = new Processer();
     $child = new Child();
     /*$person1->on(Person::ACTION_EAT, [$processer, 'cook']);
       $person2->on(Person::ACTION_EAT, [$processer, 'cook']);*/
     /*类级事件处理*/
     Event::on(Person::className(), Person::ACTION_EAT, [$processer, 'cook']);
     $person1->on(Person::ACTION_EAT, [$processer, 'order3']);
     $person1->eat();
     echo Person::SEPARATOR;
     $person2->eat();
     echo Person::SEPARATOR;
     $child->eat();
 }
コード例 #2
0
ファイル: Department.php プロジェクト: komsin/yiiexpert1
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPeople()
 {
     return $this->hasMany(Person::className(), ['department_id' => 'department_id']);
 }
コード例 #3
0
ファイル: Prefix.php プロジェクト: komsin/yiiexpert1
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPeople()
 {
     return $this->hasMany(Person::className(), ['prefix_id' => 'prefix_id']);
 }
コード例 #4
0
 public function eat()
 {
     echo 'This is person eating.<br><br>';
     /* $this->trigger(self::ACTION_EAT);*/
     Event::trigger(Person::className(), self::ACTION_EAT);
 }