Answers.Body: <p>Yii fires the onBeginRequest event before Craft has had a chance to do any of the plugin bootstrapping / initialization, which is why it's not firing in your plugin.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-08T17:08:39.030Z
Answers.LastActivityDate: 2014-08-08T17:08:39.030Z
Answers.UserDisplayName: Brad Bell
Body: <p>I want to listen for Yii events like onBeginRequest and onEndRequest. I've tried the following but nothing happens :( </p>
  
  <pre><code>\Yii::app()-&gt;onBeginRequest = create_function('$event', 'die ("YO") ;');
  </code></pre>
  
  <p>and </p>
  
  <pre><code>craft()-&gt;attachEventHandler('onBeginRequest', array($this, 'dieyo'));
  </code></pre>
  
  <p>and</p>
  
  <pre><code>craft()-&gt;getEventHandlers('onBeginRequest')-&gt;add(array($this, 'dieyo'));
  </code></pre>
  
  <p>-</p>
  
  <pre><code>public function dieyo($event)
  {
      craftdd($event);
  }
  </code></pre>
  
  <p>Thanks in advance</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-08-08T14:49:21.870Z
Comments.Text: Did some more testing "onEndRequest" works fine. So I guess onBeginRequest is a loader and/or timing issue?
Comments.UserDisplayName: pythic
Tags: <plugin-development><events>
Title: Is it possible to listen for Yii events?
ThreadText: # Is it possible to listen for Yii events?
  
  (Asked by: username_0 on 2014-08-08)
  
  I want to listen for Yii events like onBeginRequest and onEndRequest. I've tried the following but nothing happens :(
  
  ```
  \Yii::app()->onBeginRequest = create_function('$event', 'die ("YO") ;');
  
  ```
  
  and
  
  ```
  craft()->attachEventHandler('onBeginRequest', array($this, 'dieyo'));
  
  ```
  
  and
  
  ```
  craft()->getEventHandlers('onBeginRequest')->add(array($this, 'dieyo'));
  
  ```
  
  -
  
  ```
  public function dieyo($event)
  {
      craftdd($event);
  }
  
  ```
  
  Thanks in advance
  
  **Tags:** plugin-development, events
  
  > **Comments:**
  > **username_0**: Did some more testing "onEndRequest" works fine. So I guess onBeginRequest is a loader and/or timing issue?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-08-08. Score: 2 | Accepted answer
  
  Yii fires the onBeginRequest event before Craft has had a chance to do any of the plugin bootstrapping / initialization, which is why it's not firing in your plugin.
  
  
  ---
  
  