title: Create a pull event in yii
body: <p>My problem is that I want to create an event in Yii where you don't have to push the function which is being called when an event is called. As you can see in the example method "sendMailToAdmin" is called specifically when the event is called. But we can not call this a proper event, as we are just calling a method in another method. I want to just raise an event and then a method can check if that event is called and then it can run itself. This will be a pull operation instead of the push operation. Is this possible using Yii event? Also, i don't want to use any socket programming to solve this. </p>
  
  <p>For example - If I want to add user role in the <code>user_role</code> table when a user is created then, the <code>UserRole</code> model should be able to catch this event and create a new entry in user role table. Instead of attaching event using <code>on</code> in <code>init</code> of <code>MyUser</code> model  </p>
  
  <p>Here is my code</p>
  
  <pre><code>&lt;?php
     namespace app\models;
     use Yii;
     /**
     * This is the model class for table "user".
     *
     * @property integer $id
     * @property string $name
     * @property string $email
     */
     class MyUser extends \yii\db\ActiveRecord {
        const EVENT_NEW_USER = 'new-user';
        public function init() {
           // first parameter is the name of the event and second is the handler.
           $this-&gt;on(self::EVENT_NEW_USER, [$this, 'sendMailToAdmin']);
        }
        /**
        * @inheritdoc
        */
        public static function tableName() {
           return 'user';
        }
        /**
        * @inheritdoc
        */
        public function rules() {
           return [
              [['name', 'email'], 'string', 'max' =&gt; 255]
           ];
        }
        /**
        * @inheritdoc
        */
        public function attributeLabels() {
           return [
              'id' =&gt; 'ID',
              'name' =&gt; 'Name',
              'email' =&gt; 'Email',
           ];
        }
        public function sendMailToAdmin($event) {
           echo 'mail sent to admin using the event';
        }
      }
      ?&gt;
  
     public function actionTestEvent() {
     $model = new MyUser();
     $model-&gt;name = "John";
     $model-&gt;email = "john@gmail.com";
     if($model-&gt;save()) {
        $model-&gt;trigger(MyUser::EVENT_NEW_USER);
     }
     }
  </code></pre>